Skip to content

Commit

Permalink
Export ErrInvalidFilterExpression error
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanahuckova committed Oct 7, 2024
1 parent fed9ce0 commit 98a95cb
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
4 changes: 4 additions & 0 deletions lib/go/transformations/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# @grafana/infinity-transformations

## 1.0.3

- ⚙️ **Chore**: improved error messages

## 1.0.2

- ⚙️ **Chore**: improved error messages
Expand Down
2 changes: 1 addition & 1 deletion lib/go/transformations/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var (
ErrSummarizeByFieldNotFound = errors.New("summarize by field not found. Not applying summarize")
ErrNotUniqueFieldNames = errors.New("field names are not unique. Not applying filter")
ErrEvaluatingFilterExpression = errors.New("error evaluating filter expression")
ErrInvalidToken = errors.New("invalid token")
ErrInvalidFilterExpression = errors.New("invalid filter expression")

ErrMergeTransformationNoFrameSupplied = errors.New("no frames supplied for merge frame transformation")
ErrMergeTransformationDifferentFields = errors.New("unable to merge fields due to different fields")
Expand Down
10 changes: 10 additions & 0 deletions lib/go/transformations/filterExpression.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ func ApplyFilter(frame *data.Frame, filterExpression string) (*data.Frame, error
}
parsedExpression, err := govaluate.NewEvaluableExpressionWithFunctions(filterExpression, ExpressionFunctions)
if err != nil {
if checkIfInvalidFilterExpression(err) {
return frame, fmt.Errorf("%w. %w", ErrInvalidFilterExpression, err)
}
return frame, err
}
fieldKeys := map[string]bool{}
Expand Down Expand Up @@ -75,3 +78,10 @@ func ApplyFilter(frame *data.Frame, filterExpression string) (*data.Frame, error
}
return filteredFrame, nil
}


func checkIfInvalidFilterExpression(err error) bool {
// Check if the error is due to an invalid token
// This error is not exported by the govaluate library, so we need to check the error message
return strings.Contains(err.Error(), "Invalid token:")
}
2 changes: 1 addition & 1 deletion lib/go/transformations/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@grafana/infinity-transformations",
"private": true,
"version": "1.0.2",
"version": "1.0.3",
"scripts": {
"tidy": "go mod tidy",
"test:backend": "go test -v ./..."
Expand Down

0 comments on commit 98a95cb

Please sign in to comment.