-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patherror.go
49 lines (41 loc) · 928 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
//go:generate stringer -type=ParseError -output=error_string.go
package lzjson
// ParseError describe error natures in parsing process
type ParseError int
// types of error
const (
ErrorUndefined ParseError = iota
ErrorNotObject
ErrorNotArray
)
func (err ParseError) Error() string {
switch err {
case ErrorUndefined:
return "undefined"
case ErrorNotObject:
return "not an object"
case ErrorNotArray:
return "not an array"
}
return "unknown parse error"
}
// GoString implements fmt.GoStringer
func (err ParseError) GoString() string {
return "lzjson." + err.String()
}
// Error is the generic error for parsing
type Error struct {
Path string
Err error
}
// Error implements error type
func (err Error) Error() string {
if err.Path != "" {
return err.Path + ": " + err.Err.Error()
}
return err.Err.Error()
}
// String implements Stringer
func (err Error) String() string {
return err.Error()
}