jashkenas / jashkenas/coffeescript
Bug: Error#prepareStackTrace override causes console.trace to print '[object Object]' to the console.
- Dominant language
- CoffeeScript
- Stars
- 16.6k
- Forks
- 2k
- PR merge metrics
- No merged PRs in 30d
Description
### Input Code
```js
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 (:17:15)
...
```
while it should look like this
```
Trace: My Trace
at console.trace (: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
Contributor guide
Research direction
Start in lib/coffeescript/coffeescript.js at the linked prepareStackTrace method and reproduce the issue with the provided CoffeeScript require and console.trace snippet. Confirm that the output preserves the trace name and message as “Trace: My Trace” rather than “[object Object]”, then add coverage for the plain object passed by console.trace.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- coffeescript, node.js
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100