diff --git a/CHANGELOG.md b/CHANGELOG.md index f641cf2da7..770665e5da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,16 @@ # Changelog +## v1.0.0-beta2 [unreleased] + +### Release Notes + +### Features + +### Bugfixes + +- [#621](https://github.com/influxdata/kapacitor/pull/621): Fix obscure error about single vs double quotes. + + ## v1.0.0-beta1 [2016-06-06] ### Release Notes diff --git a/tick/eval.go b/tick/eval.go index bbf26876f6..779fc32b9e 100644 --- a/tick/eval.go +++ b/tick/eval.go @@ -239,7 +239,10 @@ func eval(n ast.Node, scope *stateful.Scope, stck *stack, predefinedVars, defaul ret := stck.Pop() if f, ok := ret.(unboundFunc); ok { // Call global function - f(nil) + _, err := f(nil) + if err != nil { + return err + } } } } @@ -483,9 +486,9 @@ func evalFunc(f *ast.FunctionNode, scope *stateful.Scope, stck *stack, args []in rec := func(obj interface{}, errp *error) { e := recover() if e != nil { - *errp = fmt.Errorf("line %d char%d: error calling func %q on obj %T: %v", f.Line(), f.Char(), f.Func, obj, e) - if strings.Contains((*errp).Error(), "*tick.ReferenceNode") && strings.Contains((*errp).Error(), "type string") { - *errp = fmt.Errorf("line %d char%d: cannot assign *tick.ReferenceNode to type string, did you use double quotes instead of single quotes?", f.Line(), f.Char()) + *errp = fmt.Errorf("line %d char %d: error calling func %q on obj %T: %v", f.Line(), f.Char(), f.Func, obj, e) + if strings.Contains((*errp).Error(), "*ast.ReferenceNode") && strings.Contains((*errp).Error(), "type string") { + *errp = fmt.Errorf("line %d char %d: cannot assign *ast.ReferenceNode to type string, did you use double quotes instead of single quotes?", f.Line(), f.Char()) } } @@ -496,12 +499,12 @@ func evalFunc(f *ast.FunctionNode, scope *stateful.Scope, stck *stack, args []in if f.Type == ast.GlobalFunc { if obj != nil { - return nil, fmt.Errorf("line %d char%d: calling global function on object %T", f.Line(), f.Char(), obj) + return nil, fmt.Errorf("line %d char %d: calling global function on object %T", f.Line(), f.Char(), obj) } // Object is nil, check for func in scope fnc, _ := scope.Get(f.Func) if fnc == nil { - return nil, fmt.Errorf("line %d char%d: no global function %q defined", f.Line(), f.Char(), f.Func) + return nil, fmt.Errorf("line %d char %d: no global function %q defined", f.Line(), f.Char(), f.Func) } method := reflect.ValueOf(fnc) o, err := callMethodReflection(method, args) diff --git a/tick/eval_test.go b/tick/eval_test.go index e188b823fd..2ca53f26fb 100644 --- a/tick/eval_test.go +++ b/tick/eval_test.go @@ -818,16 +818,34 @@ f(strList) scope := stateful.NewScope() scope.Set("f", f) - vars, err := tick.Evaluate(script, scope, nil, false) + _, err := tick.Evaluate(script, scope, nil, false) if err != nil { t.Fatal(err) } - t.Log(vars) if !called { t.Fatal("expected function to be called") } } +func TestEvaluate_StringQuotesError(t *testing.T) { + script := ` +f("asdf") +` + + f := func(got string) { + t.Fatal("function should not be called") + } + scope := stateful.NewScope() + scope.Set("f", f) + + _, err := tick.Evaluate(script, scope, nil, false) + if err == nil { + t.Fatal("expected error from invalid string call") + } else if got, exp := err.Error(), "line 2 char 1: cannot assign *ast.ReferenceNode to type string, did you use double quotes instead of single quotes?"; got != exp { + t.Errorf("unexpected error string: \ngot\n%s\nexp\n%s\n", got, exp) + } +} + //------------------------------------ // Types for TestReflectionDescriber //