-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patherror.go
63 lines (50 loc) · 976 Bytes
/
error.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
61
62
63
package aseprite
import (
"strings"
)
var (
errorAnimationNotFound = &Error{
subject: "animation not found in aseprite file",
}
)
// Error is used as a custom error for the aseprite package.
type Error struct {
subject string
params []string
err error
}
func (e *Error) withParams(p ...string) *Error {
e.params = p
return e
}
func (e *Error) withError(err error) *Error {
e.err = err
return e
}
// Unwrap unwraps and returns the original error if one exists.
// Note: Go 1.13 change
func (e *Error) Unwrap() error {
if e.err != nil {
return e.err
}
return nil
}
func (e *Error) Error() string {
var b strings.Builder
defer b.Reset()
b.WriteString(e.subject)
if e.err != nil {
b.WriteString(": error[" + e.err.Error() + "]")
}
if len(e.params) != 0 {
b.WriteString(": params[")
for i, p := range e.params {
b.WriteString(p)
if i != len(e.params)-1 {
b.WriteByte(',')
}
}
b.WriteByte(']')
}
return b.String()
}