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

PARSE_ERROR: keep Acorn’s original message somewhere #3149

Closed
rauschma opened this issue Oct 9, 2019 · 5 comments
Closed

PARSE_ERROR: keep Acorn’s original message somewhere #3149

rauschma opened this issue Oct 9, 2019 · 5 comments

Comments

@rauschma
Copy link

rauschma commented Oct 9, 2019

Expected Behavior / Situation

Actual Behavior / Situation

Modification Proposal

Context: src/Module.ts

} else if (!module.id.endsWith('.js')) {
  message += ' (Note that you need plugins to import files that are not JavaScript)';
}
  • Suggestion for improvement: For error reporting, it would be useful to also have access to Acorn’s original error message, e.g. via a property .parserMessage.
  • Observation: module.id.endsWith('.js') may need to be changed to also accommodate .mjs.

Note by maintainers (by @lukastaegert)

🙋‍♀️ Want to get involved and address this? This issue is likely easy to address and a good starting point to get familiar with the Rollup code base.

The proposed solution is here

} catch (err) {
to attach the original error as an additional parserError property to the object passed to module.error. For that, the RollupError type will need to be extended with an additional optional property.

To test this, a test in the function folder makes sense as those tests are capable of checking error messages, cf. e.g. this test:

description: 'throws on duplicate named exports',
error: {
code: 'PARSE_ERROR',
message: `Duplicate export 'foo'`,
pos: 38,
watchFiles: [path.resolve(__dirname, 'main.js'), path.resolve(__dirname, 'foo.js')],
loc: {
file: path.resolve(__dirname, 'foo.js'),
line: 3,
column: 9
},
frame: `
1: var foo = 1;
2: export { foo };
3: export { foo };
^
`
}

@lukastaegert
Copy link
Member

I see no reason why we should not address this, the improvement would be easy and unlikely to break anything. Maybe as a small change, as I am not 100% sold on the name parserMessage, we could add a property .parserError the contains the original error object. This could also be used to debug issues within acorn or from interactions with acorn plugins via the stack trace. As I currently try to get more people involved, I will add some implementation notes to the description for whoever wants to pick this up.

@gribnoysup
Copy link
Contributor

I would love to help with this one 🙌

@lukastaegert
Copy link
Member

Nice! As no one else volunteered yet, the issue can be yours. As you probably saw in the description, I added some notes as to what I think needs to be done, just tell me if you need more info. If you are unsure, you can also just start a PR and we can talk about it there. New contributors are always very much welcome!

@lukastaegert
Copy link
Member

BTW I actually think you do not need to add a new test, it is probably enough to fix the tests that check for a PARSE_ERROR.

@lukastaegert
Copy link
Member

Resolved via #3176

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

No branches or pull requests

3 participants