-
-
Notifications
You must be signed in to change notification settings - Fork 30
Description
This is a proposal to support printing stacks of errors nested with error.cause
. The JS spec allows error.cause
to be any value, but this proposal is mainly concerned with what happens when cause
is present as a string or another error.
I've written up the most descriptive form of this proposal as a proposed jest feature. If you don't mind I'll avoid copying it all out here. Jest uses stack-utils
under the hood to reformat errors.
The TC39 committee has so far indicated that the language will not provide any official implementation of printing nested errors. Their hands are tied to some extent until they finish specifying the semantics of error.stack
. But until then it will be very useful to have best-effort printing and formatting for errors printed in the most common way.
I think errors with causes should be printed more or less like this:
SomeError: The grumblecakes could not be found
at grumblecake-locator.js:12:2
Caused by: QueryError: Invalid query `SELECT <grumblecakes>`
at db.js:51:4
Caused by: ParseError: Unexpected character `<` at position 8
at db.js:1233:10
Currently there is no standard for this. I think stack-utils
would be an excellent library in which to create an implementation which formats, prints, and loosely parses errors with multiple messages and stack traces.
I'm willing to build it. Is there interest from the maintainers?