Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for merging stacktrace of inner exceptions #22

Closed
petamoriken opened this issue Jan 14, 2019 · 2 comments
Closed

Support for merging stacktrace of inner exceptions #22

petamoriken opened this issue Jan 14, 2019 · 2 comments

Comments

@petamoriken
Copy link

@petamoriken petamoriken commented Jan 14, 2019

Some custom error packages, e.g. extensible-custom-error and trace-error, support for holding inner exceptions and emitting it in stacktrace. Please support this in spec (add to #1 list?).

If you run:

const ExtensibleCustomError = require('extensible-custom-error');

class MyError extends ExtensibleCustomError {}

function throwBuiltinError() {
  throw new Error('Have withstood Pain to create many Weapons');
}

function wrapErrorWithMyError() {
  try {
    throwBuiltinError();
  } catch (error) {
    throw new MyError('Unlimited Blade Works', error);
  }
}

function main() {
  try {
    wrapErrorWithMyError();
  } catch (error) {
    console.log(error);
  }
}

main();

you'll get:

MyError: Unlimited Blade Works
    at wrapErrorWithMyError (/home/necojackarc/custom_error.js:101:11)
Error: Have withstood Pain to create many Weapons
    at throwBuiltinError (/home/necojackarc/custom_error.js:94:9)
    at wrapErrorWithMyError (/home/necojackarc/custom_error.js:99:5)
    at main (/home/necojackarc/custom_error.js:107:5)
    at Object.<anonymous> (/home/necojackarc/custom_error.js:113:1)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Function.Module.runMain (module.js:693:10)

https://github.com/necojackarc/extensible-custom-error/blob/master/README.md#wrap-an-error-while-passing-a-new-message

@ljharb

This comment has been minimized.

Copy link
Member

@ljharb ljharb commented Jan 14, 2019

This isn't how any JS engines work - error constructors only take one argument, and there's no such thing as "nested errors".

It's an interesting proposal, but it'd need to be a separate one, since it'd need to change every built-in Error constructor.

@ljharb ljharb closed this Jan 14, 2019
@petamoriken

This comment has been minimized.

Copy link
Author

@petamoriken petamoriken commented Jan 14, 2019

I found this topic in ES Discuss. I appreciate your help.
https://esdiscuss.org/topic/error-caused-by-other-error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.