coffeescript icon indicating copy to clipboard operation
coffeescript copied to clipboard

Bug: Error#prepareStackTrace override causes console.trace to print '[object Object]' to the console.

Open BannerBomb opened this issue 3 years ago • 0 comments

Input Code

require('coffeescript');
console.trace('My Trace');

The above should show a stacktrace with the name Trace: My Trace but instead of outputs [object Object]. This is due to this method https://github.com/jashkenas/coffeescript/blob/07f644c39223e016aceedd2cd71b5941579b5659/lib/coffeescript/coffeescript.js#L435-L462 since console.trace isn't an error instance but rather an object with a name and message property. In which calling toString on an object outputs [object Object].

Expected Behavior

It was expected to handle the trace message object properly instead of calling toString in it.

Current Behavior

prepareStackTrace is calling toString on the error object but console.trace sends a plain object with a name, message and stack keys. The stack trace ends up looking like this

[object console]
    at console.trace (<anonymous>:17:15)
    ...

while it should look like this

Trace: My Trace
    at console.trace (<anonymous>:17:15)
    ...

Possible Solution

Context

It didn't really affect me much, just made it harder to distinguish traces from one another since all of the names were [object Object]

Environment

  • CoffeeScript version: v2.5.1
  • Node.js version: v15.7.0

BannerBomb avatar Feb 14 '21 02:02 BannerBomb