-
Notifications
You must be signed in to change notification settings - Fork 0
/
error.go
65 lines (54 loc) · 1.74 KB
/
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
64
65
package json6
import (
"errors"
"fmt"
)
func errInvalidChar(invChar rune, pos *Position, nearChars []rune, expecting string) error {
return fmt.Errorf("invalid character '%s' at %d:%d near '%s', expecting %s", string([]rune{invChar}), pos.Line(), pos.Column(), string(nearChars), expecting)
}
func errUnexpectedEOF(pos *Position, expecting string) error {
return fmt.Errorf("unexpected EOF at %d:%d, expecting %s", pos.Line(), pos.Column(), expecting)
}
func errUnexpectedToken(token Token, expects ...string) error {
expectsLen := len(expects)
var expectStr string
if expectsLen > 1 {
for i, expect := range expects {
if i < expectsLen-1 {
expectStr += expect + ", "
} else {
expectStr += "or " + expect
}
}
} else {
expectStr = expects[0]
}
return fmt.Errorf("unexpected token '%s' (%s) at %d:%d, expecting %s", token.String(), token.TypeString(), token.StartPos.ln, token.StartPos.col, expectStr)
}
func errUnexpectedEndOfTokenStream(expects ...string) error {
expectsLen := len(expects)
var expectStr string
if expectsLen > 1 {
for i, expect := range expects {
if i < expectsLen-1 {
expectStr += expect + ", "
} else {
expectStr += "or " + expect
}
}
} else {
expectStr = expects[0]
}
return fmt.Errorf("unexpected end of token stream, expecting %s", expectStr)
}
func errMismatchType(src []rune, srcType, valType string) error {
return fmt.Errorf("can not decode %s (%s) to type %s", string(src), srcType, valType)
}
func errDecodeToNilPtr() error {
return errors.New("can not decode to nil pointer")
}
func errDecodeToNonPtr() error {
return errors.New("can not decode to non pointer")
}
var ErrNoMoreToken = errors.New("no more token")
var ErrAlreadyAtBeginning = errors.New("already at beginning")