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

Re-throw compilation errors with additional information #115

Merged
merged 1 commit into from
Jun 9, 2017
Merged

Re-throw compilation errors with additional information #115

merged 1 commit into from
Jun 9, 2017

Conversation

twokul
Copy link

@twokul twokul commented Jun 3, 2017

Depends on glimmerjs/glimmer-vm#540.

Once we agree on BuildError interface, we can replace the code in a catch block to:

import { BuildError } from 'ember-build-utilities';

// code

try {
  // code
} catch(e) {
  throw new BuildError('Template Compiler Error', e.message, e.stack, e.location.start);
}

index.js Outdated
} catch(e) {
// Create a new error, augment it with location and type information
// and re-throw.
let error = new Error(e);
Copy link
Member

Choose a reason for hiding this comment

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

Seems slightly odd. Why don't we just add the props we need/want to the existing error? I think as it stands we loose the original stack info?

Also, I believe that broccoli-persistent-filter also wraps in a try / catch so that it can add the file name info...

Copy link
Author

Choose a reason for hiding this comment

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

I don't think broccoli-persistent-filter wraps in try-catch but maybe I'm wrong? looking here.

as far as why not attaching properties to existing error -- my thinking was that we're going to use one BuildError class to communicate exceptions and would ideally want to just throw new BuildError() w/o add-on developers knowing too much about which properties need to be attached. Having said that, in this particular case, we don't necessarily need to create a new Error object and can re-throw after attaching info we need.

Copy link
Member

Choose a reason for hiding this comment

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

I don't think broccoli-persistent-filter wraps in try-catch but maybe I'm wrong?

https://github.com/stefanpenner/broccoli-persistent-filter/blob/master/index.js#L283-L288

index.js Outdated
} catch(error) {
// augment with location and type information and re-throw.
error.type = 'Template Compiler Error';
error.location = error.location.start;
Copy link
Contributor

Choose a reason for hiding this comment

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

Error might not be an object and even if it is it may not have location. This catch clause will likely need to be slightly more resilient

Copy link
Author

Choose a reason for hiding this comment

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

oh? error here comes from ember-template-compiler/broccoli-persistent-filter and I thought it always is going to be an object. As far as location property goes, it should be there because glimmerjs/glimmer-vm#540.

having said that, I'm happy to make it more resilient

Copy link
Contributor

Choose a reason for hiding this comment

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

@twokul ya, I would prefer if this was made more resilient as bit-rot or unexpected errors can always change what catch ends up catching.

Its literally the worst to have a catch handler throw when a different bug happened. So if we can beef up this catch handler, it will help mitigate future sadness.

Copy link
Member

@rwjblue rwjblue left a comment

Choose a reason for hiding this comment

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

LGTM

@stefanpenner - Wanna do another round?

@@ -7,6 +7,20 @@ const crypto = require('crypto');
const stringify = require('json-stable-stringify');
const stripBom = require('strip-bom');

function rethrowBuildError(error) {
if (!error) { throw new Error('Unknown Error'); }
Copy link
Contributor

Choose a reason for hiding this comment

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

i believe we can still share realtivePath in some useful way if we throw here. RIght?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, but that is handled a layer down (in broccoli-persistent-filter itself)

Copy link
Contributor

Choose a reason for hiding this comment

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

ah good point

@stefanpenner stefanpenner merged commit a390bc3 into ember-cli:master Jun 9, 2017
@stefanpenner
Copy link
Contributor

released as v2.0.2 🎉

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

3 participants