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

Plugin throwing Error with numeric code causes TypeError within Rollup itself #5036

Closed
nolanlawson opened this issue Jun 13, 2023 · 5 comments · Fixed by #5042
Closed

Plugin throwing Error with numeric code causes TypeError within Rollup itself #5036

nolanlawson opened this issue Jun 13, 2023 · 5 comments · Fixed by #5042

Comments

@nolanlawson
Copy link
Contributor

Rollup Version

3.25.1

Operating System (or Browser)

MacOS

Node Version (if applicable)

16

Link To Reproduction

https://stackblitz.com/edit/rollup-repro-hc1mbx?file=rollup.config.js

Expected Behaviour

When a plugin throws an error with a numeric code, like so:

transform() {
  const error = new Error();
  error.code = 1234;
  throw error;
},

... I would expect this to go through the normal Rollup plugin error reporting process.

Actual Behaviour

An error is thrown from within Rollup itself:

TypeError: error.code.startsWith is not a function

This error comes from this line of code:

if (error.code && !error.code.startsWith('PLUGIN_') && !error.pluginCode) {

...and seems to have been introduced in 23c111c (Rollup v3.25.0).

The assumption seems to be that, if error.code is truthy, then it's a string type. However, a plugin may throw an Error with a numeric type for error.code.

@TrickyPi
Copy link
Member

TrickyPi commented Jun 14, 2023

For customized errors in Plugin, I personally recommend using this.error api with type hints, it will tell us that Rollup expects code to be of type string.

@nolanlawson
Copy link
Contributor Author

@TrickyPi That's totally reasonable, but unless I wrap everything in my plugin in a try/catch, I cannot be sure that I don't have some deep dependency that is throwing an Error with a numeric code.

@TrickyPi
Copy link
Member

Hmm, fair enough.

@lukastaegert
Copy link
Member

Yes, definitely an oversight. Unfortunately as I am travelling at the moment, fixing it will require at least another week.

@rollup-bot
Copy link
Collaborator

This issue has been resolved via #5042 as part of rollup@3.25.2. You can test it via npm install rollup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants