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

Normalize code frames on thrown errors so that code always exists #5115

Open
Aaronius opened this issue Sep 8, 2020 · 3 comments
Open

Normalize code frames on thrown errors so that code always exists #5115

Aaronius opened this issue Sep 8, 2020 · 3 comments

Comments

@Aaronius
Copy link

Aaronius commented Sep 8, 2020

🙋 feature request

When using the Parcel API and an error is thrown, there's no guarantee that error.diagnostics.*.codeFrame.code exists. If it doesn't then the consumer of the API has to duplicate this logic to retrieve the code pertaining to the code frame:

let code =
codeFrame.code ??
(options &&
(await options.inputFS.readFile(nullthrows(filePath), 'utf8')));

This is kind of a pain. I would love to see Parcel normalize these errors so that when a consumer receives a code frame on an error, the code property always exists and the consumer doesn't have to bother with reading source files directly.

🤔 Expected Behavior

I would expect the code property to always exists on any code frame being reported by Parcel.

😯 Current Behavior

The code property only sometimes exists on a code frame.

💁 Possible Solution

If a plugin doesn't provide the code property, Parcel could add it before the error makes its way to the Parcel consumer.

🔦 Context

This is described in further detail in #5081.

💻 Examples

@mischnic
Copy link
Member

mischnic commented Sep 8, 2020

to the Parcel consumer

That is: reporters and the BuildError thrown when using the API

@hiteshvijayhv
Copy link

I would like to claim this issue

@DeMoorJasper
Copy link
Member

Sure, feel free to take this.

Interested in what the performance impacts for this would be.

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

4 participants