Repository navigation
Expand file tree
/
Copy patherror.go
More file actions
75 lines (69 loc) · 1.69 KB
/
Copy patherror.go
File metadata and controls
75 lines (69 loc) · 1.69 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
package syntax
import "strconv"
// ErrorCode identifies a stable category of parsing failure.
type ErrorCode uint8
const (
InvalidEncoding ErrorCode = iota + 1
InvalidCharacter
InvalidType
InvalidScope
InvalidSeparator
InvalidDescription
InvalidSectionSeparator
InvalidFooterValue
)
func (c ErrorCode) String() string {
switch c {
case InvalidEncoding:
return "InvalidEncoding"
case InvalidCharacter:
return "InvalidCharacter"
case InvalidType:
return "InvalidType"
case InvalidScope:
return "InvalidScope"
case InvalidSeparator:
return "InvalidSeparator"
case InvalidDescription:
return "InvalidDescription"
case InvalidSectionSeparator:
return "InvalidSectionSeparator"
case InvalidFooterValue:
return "InvalidFooterValue"
default:
return "ErrorCode(" + strconv.Itoa(int(c)) + ")"
}
}
// ParseError locates a failure in the original input. Offset is a zero-based
// byte position and may equal the input length for missing content.
type ParseError struct {
Code ErrorCode
Offset int
}
func (e *ParseError) Error() string {
if e == nil {
return "<nil>"
}
var reason string
switch e.Code {
case InvalidEncoding:
reason = "invalid UTF-8"
case InvalidCharacter:
reason = "invalid character"
case InvalidType:
reason = "invalid type"
case InvalidScope:
reason = "invalid scope"
case InvalidSeparator:
reason = "expected colon and space"
case InvalidDescription:
reason = "expected nonblank description"
case InvalidSectionSeparator:
reason = "expected blank line before content"
case InvalidFooterValue:
reason = "expected nonblank footer value"
default:
reason = "invalid input"
}
return "syntax: " + reason + " at byte " + strconv.Itoa(e.Offset)
}