diff --git a/rule/logic/common.go b/rule/logic/common.go index 61dbe963..0f43e688 100644 --- a/rule/logic/common.go +++ b/rule/logic/common.go @@ -62,21 +62,18 @@ func payloadToRule(subPayload string) (C.Rule, error) { } func parseRule(tp, payload string, params []string) (parsed C.Rule, parseErr error) { - parsed, parseErr = ruleparser.ParseSameRule(tp, payload, "", params) - if ruleparser.IsUnsupported(parseErr) { - switch tp { - case "AND": - parsed, parseErr = NewAND(payload, "") - case "OR": - parsed, parseErr = NewOR(payload, "") - case "NOT": - parsed, parseErr = NewNOT(payload, "") - case "RULE-SET": - noResolve := RC.HasNoResolve(params) - parsed, parseErr = RP.NewRuleSet(payload, "", noResolve) - default: - parseErr = ruleparser.NewUnsupportedError(tp) - } + switch tp { + case "AND": + parsed, parseErr = NewAND(payload, "") + case "OR": + parsed, parseErr = NewOR(payload, "") + case "NOT": + parsed, parseErr = NewNOT(payload, "") + case "RULE-SET": + noResolve := RC.HasNoResolve(params) + parsed, parseErr = RP.NewRuleSet(payload, "", noResolve) + default: + parsed, parseErr = ruleparser.ParseSameRule(tp, payload, "", params) } if parseErr != nil { diff --git a/rule/parser.go b/rule/parser.go index cc76219c..05d01e32 100644 --- a/rule/parser.go +++ b/rule/parser.go @@ -9,24 +9,21 @@ import ( ) func ParseRule(tp, payload, target string, params []string) (parsed C.Rule, parseErr error) { - parsed, parseErr = ruleparser.ParseSameRule(tp, payload, target, params) - if ruleparser.IsUnsupported(parseErr) { - switch tp { - case "AND": - parsed, parseErr = logic.NewAND(payload, target) - case "OR": - parsed, parseErr = logic.NewOR(payload, target) - case "NOT": - parsed, parseErr = logic.NewNOT(payload, target) - case "RULE-SET": - noResolve := RC.HasNoResolve(params) - parsed, parseErr = RP.NewRuleSet(payload, target, noResolve) - case "MATCH": - parsed = RC.NewMatch(target) - parseErr = nil - default: - parseErr = ruleparser.NewUnsupportedError(tp) - } + switch tp { + case "AND": + parsed, parseErr = logic.NewAND(payload, target) + case "OR": + parsed, parseErr = logic.NewOR(payload, target) + case "NOT": + parsed, parseErr = logic.NewNOT(payload, target) + case "RULE-SET": + noResolve := RC.HasNoResolve(params) + parsed, parseErr = RP.NewRuleSet(payload, target, noResolve) + case "MATCH": + parsed = RC.NewMatch(target) + parseErr = nil + default: + parsed, parseErr = ruleparser.ParseSameRule(tp, payload, target, params) } if parseErr != nil { diff --git a/rule/ruleparser/ruleparser.go b/rule/ruleparser/ruleparser.go index c4bd7bad..55f63f82 100644 --- a/rule/ruleparser/ruleparser.go +++ b/rule/ruleparser/ruleparser.go @@ -44,24 +44,7 @@ func ParseSameRule(tp, payload, target string, params []string) (parsed C.Rule, case "IN-TYPE": parsed, parseErr = RC.NewInType(payload, target) default: - parseErr = NewUnsupportedError(tp) + parseErr = fmt.Errorf("unsupported rule type %s", tp) } return } - -type UnsupportedError struct { - err string -} - -func (ue UnsupportedError) Error() string { - return ue.err -} - -func NewUnsupportedError(tp any) *UnsupportedError { - return &UnsupportedError{err: fmt.Sprintf("unsupported rule type %s", tp)} -} - -func IsUnsupported(err error) bool { - _, ok := err.(*UnsupportedError) - return ok -}