Skip to content

Commit

Permalink
Don't run errors through fmt.Sprintf when not necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
mstoykov committed May 16, 2022
1 parent e1eca0b commit b2242cc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ func (r *Runtime) NewTypeError(args ...interface{}) *Object {
}

func (r *Runtime) NewGoError(err error) *Object {
e := r.newError(r.global.GoError, err.Error()).(*Object)
e := r.builtin_new(r.global.GoError, []Value{newStringValue(err.Error())})
e.Set("value", err)
return e
}
Expand Down
9 changes: 9 additions & 0 deletions runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2482,3 +2482,12 @@ func BenchmarkAsciiStringMapGet(b *testing.B) {
}
}
}

func TestErrorStrangeSymbols(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())
}
}

0 comments on commit b2242cc

Please sign in to comment.