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

Surface Bundler error to browser #1457

Merged
merged 2 commits into from Jun 14, 2018

Conversation

mohsen1
Copy link
Contributor

@mohsen1 mohsen1 commented May 29, 2018

Instead of sending a generic error with the 500 response, print the error message and stack trace in the response HTML payload.

Feel free to comment.

screen shot 2018-05-31 at 4 23 03 am

@DeMoorJasper
Copy link
Member

Seems like an awesome idea, as we already have the overlay

@mohsen1
Copy link
Contributor Author

mohsen1 commented May 30, 2018

Currently I'm stuck with pretty printing output of babel-code-frame in HTML. I know that https://new.babeljs.io/repl is doing something similar (without syntax highlighting)but I'm not sure how they print the code frame. I need to look into it.

Should I consolidate this code with the overlay? Overlay is manually putting together the HTML as well. Should we depend on a templating library for generating the HTML?

@DeMoorJasper
Copy link
Member

DeMoorJasper commented May 30, 2018

@mohsen1 You can probably copy that code, unfortunately it’s in built-in so we cant create a shared function

@@ -713,7 +713,11 @@ class Bundler extends EventEmitter {

async serve(port = 1234, https = false) {
this.server = await Server.serve(this, port, https);
this.bundle();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Previously if this line was throwing an error we had a silent unhandled promise rejection

@mohsen1 mohsen1 changed the title [WIP] Surface Bundler error to browser Surface Bundler error to browser Jun 3, 2018
@codecov-io
Copy link

Codecov Report

Merging #1457 into master will increase coverage by 1.46%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1457      +/-   ##
==========================================
+ Coverage   86.41%   87.87%   +1.46%     
==========================================
  Files          80       80              
  Lines        4585     4412     -173     
==========================================
- Hits         3962     3877      -85     
+ Misses        623      535      -88
Impacted Files Coverage Δ
src/Bundler.js 93.73% <100%> (+0.3%) ⬆️
src/Server.js 92.64% <100%> (-0.34%) ⬇️
src/workerfarm/errorUtils.js 70.58% <0%> (-11.77%) ⬇️
src/visitors/dependencies.js 78.63% <0%> (-10.26%) ⬇️
src/assets/ReasonAsset.js 92.3% <0%> (-7.7%) ⬇️
src/transforms/babel.js 87.5% <0%> (-7.41%) ⬇️
src/worker.js 94.73% <0%> (-5.27%) ⬇️
src/utils/PromiseQueue.js 90.78% <0%> (-3.45%) ⬇️
src/assets/GLSLAsset.js 93.1% <0%> (-3.2%) ⬇️
... and 23 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dc10531...c257d39. Read the comment docs.

@mohsen1
Copy link
Contributor Author

mohsen1 commented Jun 5, 2018

@DeMoorJasper @devongovett Can you guys take a look? This is working :)

res.end('🚨 Build error, check the console for details.');
let errorMesssge = '<h1>🚨 Build Error</h1>';
if (process.env.NODE_ENV === 'production') {
errorMesssge += '<p><b>Check the console for details.</b></p>';
Copy link
Member

Choose a reason for hiding this comment

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

Not sure if this is necessary, the built-in parcel server should never be used in production

Copy link
Member

Choose a reason for hiding this comment

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

Parcel can be used as middleware in a production server, so I guess it's good to check this anyways.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah it should never happen but just in case...

)}</div>`;
}
}
res.end(
Copy link
Member

Choose a reason for hiding this comment

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

Why are you using an array instead of a template string here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is to make sure we're not sending extra whitespaces or not ending up with awkward code indentations. Depending on project coding style I can update.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, alright, I don't think the weird indentation matters, but that's personal taste.
I'll let someone else review this, but looks good to me

Copy link
Member

@DeMoorJasper DeMoorJasper left a comment

Choose a reason for hiding this comment

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

See comments

@mohsen1
Copy link
Contributor Author

mohsen1 commented Jun 7, 2018

@DeMoorJasper do you still require changes?

@DeMoorJasper
Copy link
Member

Looks good to me, I'm just not 100% convinced and it's a pretty large change so I'll let someone else review it

test/server.js Outdated
res.setEncoding('utf8');
let data = '';
res.on('data', c => (data += c));
res.on('end', () => {
if (Math.floor(res.statusCode / 100) !== 2) {
Copy link
Member

Choose a reason for hiding this comment

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

Does this ever respond with a code not equal to 200?
(I mean besides the error codes 404 and 500)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. My new test case has 500 response

Copy link
Member

Choose a reason for hiding this comment

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

I meant does it ever respond with something other than a standard 200 in case of a sucessfull reply.

Basically I am asking if it wouldn't be possible to use res.statusCode !== 200, seems like a less complex comparison and slightly faster probably.

As we don't set any other codes in server I think it should be safe to use !== 200

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if you ever respond with 201 or other 2xx you'll not need to update this line. I'm open to reverting back this to comparing strictly against 200 if you feel strongly about it

@mohsen1
Copy link
Contributor Author

mohsen1 commented Jun 10, 2018

@devongovett can you take a look? Thanks!

@devongovett devongovett merged commit 82a80bb into parcel-bundler:master Jun 14, 2018
devongovett pushed a commit that referenced this pull request Oct 15, 2018
devongovett pushed a commit that referenced this pull request Oct 15, 2018
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

4 participants