Skip to content

Commit

Permalink
gizmo: return error when calling filter() with a wrong type; fixes #833
Browse files Browse the repository at this point in the history
  • Loading branch information
dennwc committed Oct 7, 2019
1 parent 95d0cb2 commit 980d103
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
7 changes: 7 additions & 0 deletions query/gizmo/gizmo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,13 @@ var testQueries = []struct {
`,
expect: []string{"<charlie>"},
},
{
message: "filter with a wrong type",
query: `
g.V().filter(/<alice>/).all()
`,
err: true,
},
{
message: "use .both()",
query: `
Expand Down
4 changes: 4 additions & 0 deletions query/gizmo/traversals.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package gizmo
// Adds special traversal functions to JS Gizmo objects. Most of these just build the chain of objects, and won't often need the session.

import (
"errors"
"fmt"

"github.com/dop251/goja"
Expand Down Expand Up @@ -644,6 +645,9 @@ func (p *pathObject) Filter(args ...valFilter) (*pathObject, error) {
}
filt := make([]shape.ValueFilter, 0, len(args))
for _, f := range args {
if f.f == nil {
return nil, errors.New("invalid argument type in filter()")
}
filt = append(filt, f.f)
}
np := p.clonePath().Filters(filt...)
Expand Down

0 comments on commit 980d103

Please sign in to comment.