Skip to content

Commit

Permalink
Enhanced FECompareOp error message for invalid operators
Browse files Browse the repository at this point in the history
  • Loading branch information
nelio2k committed Apr 4, 2019
1 parent 542cb7a commit 8fa98e7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
26 changes: 25 additions & 1 deletion filterExprParser.go
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,19 @@ type FEOpChar struct {
GreaterThan *bool `@">" )`
}

func (f *FEOpChar) String() string {
if f.Not != nil {
return "!"
} else if f.Equal != nil {
return "="
} else if f.LessThan != nil {
return "<"
} else if f.GreaterThan != nil {
return ">"
}
return ""
}

type FECompareOp struct {
OpChars0 *FEOpChar `@@`
OpChars1 *FEOpChar `[ @@ ]`
Expand Down Expand Up @@ -837,7 +850,18 @@ func (feo *FECompareOp) String() string {
} else if feo.IsLessThanOrEqualTo() {
return OperatorLessThanEq
}
return "?? (FECompareOp)"
var invalidOp []string
if feo.OpChars0 != nil {
invalidOp = append(invalidOp, feo.OpChars0.String())
}
if feo.OpChars1 != nil {
invalidOp = append(invalidOp, feo.OpChars1.String())
}
if len(invalidOp) > 0 {
return strings.Join(invalidOp, "")
} else {
return "?? (FECompareOp)"
}
}

func (f *FECompareOp) OutputExpression(lhs Expression, rhs Expression) (Expression, error) {
Expand Down
5 changes: 5 additions & 0 deletions filterExprParser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -649,4 +649,9 @@ func TestFilterExpressionParser(t *testing.T) {
// Discontinued
_, _, err = NewFilterExpressionParser("SomeKey EXISTS")
assert.NotNil(err)

// Invalid operators
_, fe, err = NewFilterExpressionParser("field >< \"value\"")
_, err = fe.OutputExpression()
assert.NotNil(err)
}

0 comments on commit 8fa98e7

Please sign in to comment.