Plugin throwing Error with numeric code
causes TypeError within Rollup itself #5036
Closed
Description
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:
Line 790 in 63b7125
...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
.