proposal-error-stacks icon indicating copy to clipboard operation
proposal-error-stacks copied to clipboard

getStack() with no args, for convenience

Open trusktr opened this issue 5 years ago • 2 comments

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.

trusktr avatar Jul 10 '20 08:07 trusktr

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.

mk-pmb avatar Jul 10 '20 13:07 mk-pmb

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.

ljharb avatar Jul 11 '20 00:07 ljharb