Inverted order of errors
Turbo87 opened this issue · 6 comments
I've been looking at the tests in https://github.com/blakeembrey/make-error-cause/blob/master/src/index.spec.ts, and I think the order in which the errors are presented should probably be inverted.
The way I expect this lib to be used is something like this:
try {
somethingThatThrows();
} catch (error) {
throw new CustomError('something failed', error);
}
and then I would expect the following full trace:
CustomError: something failed
at blabla
During the above error, another error occurred:
Error: true is not false
at foobar
but if I read the tests and implementation correctly it will actually show:
Error: true is not false
at foobar
During the above error, another error occurred:
CustomError: something failed
at blabla
This seems inverted to me and not what e.g. Java does, which prints the most high-level error first.
This is based on the order Python presents nested errors. It used to be the previous order but I wanted to ensure maximum debuggability with the latest release so tried out the new order - since you’d scroll upward first.
hmm, I think in that case the seperator message ("During the above error") is wrong though
What do you believe it should be? The message was based on Python but I could use it as specified directly in https://www.python.org/dev/peps/pep-3134/#enhanced-reporting. It could also be a flag to reverse the order if you’d like that - just let me know what you think it should look like.
Looks like Python is using "The above exception was the direct cause of the following exception:", which seems to make more sense to me. I think I do prefer the Java order though
Like I mentioned, if you want a flag can be added to support it and I'm perfectly happy with that. I'd just like to know what you think it should look like. Should it say something in between like Python-style, be concatenated directly, or perhaps with a single line or whitespace?
Fixed with f22a44e. It's definitely something I was thinking about before and something I'll continue thinking about. Given the order of the JavaScript stack internally following most recent to latest (Python is inverted), it makes sense to keep the causes following the same order. I used the same message separator as Python but with "following" and "above" flipped, I'd also be open to just using a single whitespace line between each stack without text.