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

Reserve error stack information #2871

Merged
merged 4 commits into from May 27, 2019
Merged

Reserve error stack information #2871

merged 4 commits into from May 27, 2019

Conversation

LongTengDao
Copy link
Contributor

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes (bugfixes and features will not be merged without tests)
  • no

Breaking Changes?

  • yes (breaking changes will not be merged unless absolutely necessary)
  • no

List any relevant issue numbers:

Description

Help to find where the error occurred from the plugin.

Copy link
Member

@lukastaegert lukastaegert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @LongTengDao,

thanks a lot, having the original error stack is much better!

However to make the code a little simpler and rely less on the formatting of the error stack, I do not think it is necessary to combine both error stacks. After all, plugin developers only care where the error was thrown in the plugin and not where it was handled in Rollup, so how about just doing something simple like

let msg = `Could not load ${id}`;
if (importer) msg += ` (imported by ${importer})`;
msg += `: ${err.message}`;

const error = new Error(msg);
error.stack = err.stack;
throw error;

i.e. just copying the stack from the old error to the new error? The advantage would be that this code no longer relies on the exact wording of the error stack (which might break in future Node versions?)

@LongTengDao
Copy link
Contributor Author

@lukastaegert Hi!
If we don't need new stack, how about directly using the old error object, not to create it here any more?

@lukastaegert
Copy link
Member

You are right, we could just change the message 👍

@LongTengDao
Copy link
Contributor Author

@lukastaegert Done~

Copy link
Member

@lukastaegert lukastaegert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@lukastaegert lukastaegert merged commit 941e822 into rollup:master May 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants