-
Notifications
You must be signed in to change notification settings - Fork 22
/
error.go
47 lines (41 loc) · 1.54 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
package xtables
import (
"errors"
"strings"
)
var (
ErrUnsupportedAddress = errors.New("unsupported address")
ErrIllegalAddress = errors.New("illegal address")
ErrChainRequired = errors.New("chain required")
ErrCommandRequired = errors.New("command required")
ErrRulenumMustNot0 = errors.New("rulenum mustn't be 0")
ErrChainLineTooShort = errors.New("chain line too short")
ErrChainAttrsNotRecognized = errors.New("chain attrs not recognized")
ErrArgs = errors.New("wrong args")
ErrTargetNotFound = errors.New("target not found")
ErrMatchParams = errors.New("illegal match params")
ErrWatcherParams = errors.New("illegal watcher params")
ErrTargetParams = errors.New("illegal target params")
ErrAtLeastOneOptionRequired = errors.New("at least one option required")
ErrTargetParseFailed = errors.New("target parse failed")
ErrIllegalTargetType = errors.New("illegal target type")
ErrArgsWithoutMAC = errors.New("args without mac address")
)
type CommandError struct {
Err error
Message string
}
func (ce *CommandError) Error() string {
return ce.Err.Error() + ";" + ce.Message
}
func (ce *CommandError) IsRuleNotExistError() bool {
return strings.Contains(ce.Message, "rule does not exist") ||
strings.Contains(ce.Message, "does a matching rule exist in that chain?")
}
func ErrAndStdErr(err error, stderr []byte) error {
ce := &CommandError{
Err: err,
Message: string(stderr),
}
return ce
}