diff --git a/lib/go/transformations/CHANGELOG.md b/lib/go/transformations/CHANGELOG.md index 188d064..c89cb92 100644 --- a/lib/go/transformations/CHANGELOG.md +++ b/lib/go/transformations/CHANGELOG.md @@ -1,5 +1,9 @@ # @grafana/infinity-transformations +## 1.0.3 + +- ⚙️ **Chore**: improved error messages + ## 1.0.2 - ⚙️ **Chore**: improved error messages diff --git a/lib/go/transformations/errors.go b/lib/go/transformations/errors.go index 11667c7..4a1cc80 100644 --- a/lib/go/transformations/errors.go +++ b/lib/go/transformations/errors.go @@ -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") diff --git a/lib/go/transformations/filterExpression.go b/lib/go/transformations/filterExpression.go index 018fd3b..8b1f17d 100644 --- a/lib/go/transformations/filterExpression.go +++ b/lib/go/transformations/filterExpression.go @@ -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{} @@ -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:") +} \ No newline at end of file diff --git a/lib/go/transformations/package.json b/lib/go/transformations/package.json index 0ee007f..9b67c30 100644 --- a/lib/go/transformations/package.json +++ b/lib/go/transformations/package.json @@ -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 ./..."