-
Notifications
You must be signed in to change notification settings - Fork 1
/
errors.go
55 lines (48 loc) · 1002 Bytes
/
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
package visitors
import (
"fmt"
)
// ErrorType -
type ErrorType int
const (
// ErrNotSupported not supported sql syntax
ErrNotSupported ErrorType = iota
// ErrInvalidExpr invalid
ErrInvalidExpr
// ErrTypeCheck type check failed
ErrTypeCheck
// ErrCompilerError unexpected behavior in code.
ErrCompilerError
)
// Error -
type Error struct {
Type ErrorType
Detail string
}
// NewError -
func NewError(t ErrorType, detail string) Error {
return Error{
Type: t,
Detail: detail,
}
}
// NewErrorf -
func NewErrorf(t ErrorType, format string, arg ...interface{}) Error {
return Error{
Type: t,
Detail: fmt.Sprintf(format, arg...),
}
}
func (e Error) Error() string {
prefix := ""
if e.Type == ErrNotSupported {
prefix = "[NotSupported]"
} else if e.Type == ErrInvalidExpr {
prefix = "[InvalidExpr]"
} else if e.Type == ErrCompilerError {
prefix = "[CompilerError]"
} else if e.Type == ErrTypeCheck {
prefix = "[TypeCheck]"
}
return prefix + " " + e.Detail
}