dop251 / goja

ECMAScript/JavaScript engine in pure Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

errors's `stack` property always include `Error`/`GoError`/something else

mstoykov opened this issue · comments

While I was making k6's promise rejection handling a bit better I noticed that I get double GoError in all our messages as I get the "error type" both in the message and the stack.

You can see that in this test. Where the final message will be:

Uncaught (in promise) GoError: some error: GoError
      at go.k6.io/k6/js/eventloop_test.TestEventLoopRejectGoError.func1 (native)
      at <eval>:1:30(1)
      at native

I am wondering if the stack should have this at all 🤔 after all it is accessed by accessing stack so 🤷

The idea was to make it consistent with v8... However, in v8 the stack property includes error message as well as its name (I suspect it's just a result of applying Error.prototype.toString). After this is fixed you can change your code to

value = e.vu.Runtime().ToValue(fmt.Sprintf("%s\n", stack))

(although I would drop ToValue, as you seem to be only using it as a string later.