-
Notifications
You must be signed in to change notification settings - Fork 22
/
errors.go
60 lines (47 loc) · 1 KB
/
errors.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package filclient
import "fmt"
type ErrorCode int
const (
ErrUnknown ErrorCode = iota
// Failed to connect to a miner.
ErrMinerConnectionFailed
// There was an issue related to the Lotus API.
ErrLotusError
)
type Error struct {
Code ErrorCode
Inner error
}
func (code ErrorCode) String() string {
switch code {
case ErrUnknown:
return "unknown"
case ErrMinerConnectionFailed:
return "miner connection failed"
case ErrLotusError:
return "lotus error"
default:
return "(invalid error code)"
}
}
func (err *Error) Error() string {
return fmt.Sprintf("%s: %s", err.Code, err.Inner)
}
func (err *Error) Unwrap() error {
return err.Inner
}
func NewError(code ErrorCode, err error) *Error {
return &Error{
Code: code,
Inner: err,
}
}
func NewErrUnknown(err error) error {
return NewError(ErrUnknown, err)
}
func NewErrMinerConnectionFailed(err error) error {
return NewError(ErrMinerConnectionFailed, err)
}
func NewErrLotusError(err error) error {
return NewError(ErrLotusError, err)
}