tc39 / proposal-error-stacks

ECMAScript Proposal, specs, and reference implementation for Error.prototype.stack / System.getStack
https://tc39.github.io/proposal-error-stacks/
MIT License
170 stars 13 forks source link

getStack() with no args, for convenience #33

Closed trusktr closed 6 days ago

trusktr commented 4 years ago

It'd be nice if we could get a stack traces without having to instantiate an Error (because sometimes we want a stack traces and instantiating an Error just for that isn't semantic).

f.e. this would be nice:

const stack = getStack()

Instead of

const err = new Error
const stack = getStack(err)

And similar for getStackString.

mk-pmb commented 4 years ago

I'm torn between my desire for usability, and a desire to keep the spec lean, as this could easily be solved by a transpiler injecting new Error() between the parens, or a very simple library. In any case it should fail loudly if a passed-in variable happens to accidentially be undefined.

ljharb commented 4 years ago

getStack(new Error()) doesn't seem particularly burdensome to me; i'm not sure it warrants special handling.

@mk-pmb the methods will throw if anything that lacks an Error internal slot is passed into them.

mk-pmb commented 6 days ago

Theoretical use case: Someone will patch the Error constructor to count how many errors occurred in their app, so their stats will be off if we construct an error for no good reason.

ljharb commented 6 days ago

@mk-pmb that'd never work regardless, because all engine-generated errors, or errors from other realms, wouldn't be counted.