-
Notifications
You must be signed in to change notification settings - Fork 0
/
error.go
52 lines (46 loc) · 1.65 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
package rule_engine
import "fmt"
const (
Success = iota
ErrRuleEngineFuncArgument
ErrRuleEngineUnkonwnFunc
ErrRuleEngineRegexMatch
ErrRuleEngineNotSupportedVarType
ErrRuleEngineSyntaxError
ErrRuleEngineDivideByZero
ErrRuleEngineUnknownVarName
ErrRuleEngineInvalidVarType
ErrRuleEngineUnknownOperator
ErrRuleEngineNotSupportedOperator
ErrRuleEngineInvalidOperation
ErrRuleEngineInvalidParam
ErrRuleEngineParamValueTypeNotMatch
ErrRuleEngineDecimalError
)
var ERROR_MSG_MAP = map[int]string{
Success: "ok",
ErrRuleEngineFuncArgument: "func args error",
ErrRuleEngineUnkonwnFunc: "unkonwn func",
ErrRuleEngineRegexMatch: "regex error",
ErrRuleEngineNotSupportedVarType: "not supported type",
ErrRuleEngineSyntaxError: "syntax error",
ErrRuleEngineDivideByZero: "divide by zero",
ErrRuleEngineUnknownVarName: "unknown variable name",
ErrRuleEngineInvalidVarType: "invalid variable type",
ErrRuleEngineUnknownOperator: "unknown operator",
ErrRuleEngineNotSupportedOperator: "not supported operator",
ErrRuleEngineInvalidOperation: "invalid operation",
ErrRuleEngineInvalidParam: "invalid parameter",
ErrRuleEngineParamValueTypeNotMatch: "parameter value type not match",
ErrRuleEngineDecimalError: "error handle decimal",
}
type EngineErr struct {
ErrCode int
ErrMsg string
}
func (t *EngineErr) Error() string {
return fmt.Sprintf("[err]: code %v, %v, [err_msg]: %v", t.ErrCode, ERROR_MSG_MAP[t.ErrCode], t.ErrMsg)
}
func GetError(code int, msg string) *EngineErr {
return &EngineErr{ErrCode: code, ErrMsg: msg}
}