-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
errors.go
70 lines (56 loc) · 1.46 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
61
62
63
64
65
66
67
68
69
70
package parco
import (
"errors"
"fmt"
)
var (
ErrNotIntegerType = errors.New("not an integer type")
ErrOverflow = errors.New("bytes overflow")
ErrCannotRead = errors.New("unsufficient bytes read")
ErrCannotWrite = errors.New("unsufficient bytes written")
ErrAlreadyRegistered = errors.New("builder is registered already")
ErrUnknownType = errors.New("unknown type")
)
type ErrUnSufficientBytes struct {
want int
have int
}
func (e ErrUnSufficientBytes) Error() string {
return fmt.Sprintf("unsufficient bytes. want %d have %d",
e.want, e.have)
}
func NewErrUnSufficientBytesError(want, have int) ErrUnSufficientBytes {
return ErrUnSufficientBytes{
want: want,
have: have,
}
}
type ErrFieldNotFound struct {
field string
}
func (e ErrFieldNotFound) Error() string {
return "field not found " + e.field
}
func NewErrFieldNotFoundError(field string) ErrFieldNotFound {
return ErrFieldNotFound{field: field}
}
type ErrTypeAssertion struct {
expectedType string
actualType string
}
func (e ErrTypeAssertion) Error() string {
return fmt.Sprintf("unexpected type, want %s but have %s",
e.expectedType, e.actualType)
}
func NewErrTypeAssertionError(want, have string) ErrTypeAssertion {
return ErrTypeAssertion{expectedType: want, actualType: have}
}
type ErrCompile struct {
reason string
}
func (e ErrCompile) Error() string {
return e.reason
}
func NewErrCompile(reason string) ErrCompile {
return ErrCompile{reason: reason}
}