diff --git a/runtime.go b/runtime.go index eace4d61..5ba15ba0 100644 --- a/runtime.go +++ b/runtime.go @@ -470,7 +470,12 @@ func (r *Runtime) typeErrorResult(throw bool, args ...interface{}) { } func (r *Runtime) newError(typ *Object, format string, args ...interface{}) Value { - msg := fmt.Sprintf(format, args...) + var msg string + if len(args) > 0 { + msg = fmt.Sprintf(format, args...) + } else { + msg = format + } return r.builtin_new(typ, []Value{newStringValue(msg)}) } diff --git a/runtime_test.go b/runtime_test.go index 29bd293c..03dfdceb 100644 --- a/runtime_test.go +++ b/runtime_test.go @@ -2375,6 +2375,15 @@ func TestErrorStack(t *testing.T) { testScript(SCRIPT, _undefined, t) } +func TestErrorFormatSymbols(t *testing.T) { + vm := New() + vm.Set("a", func() (Value, error) { return nil, errors.New("something %s %f") }) + _, err := vm.RunString("a()") + if !strings.Contains(err.Error(), "something %s %f") { + t.Fatalf("Wrong value %q", err.Error()) + } +} + /* func TestArrayConcatSparse(t *testing.T) { function foo(a,b,c)