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

Add ability to transfer compilation errors into runtime. #208

Merged
merged 1 commit into from
May 6, 2020

Conversation

rwjblue
Copy link
Member

@rwjblue rwjblue commented May 6, 2020

Invoking the CallExpression form with a special option { insertRuntimeErrors: true } will prevent a compile time error and instead inline the error to be thrown at runtime.

So for example if a template compilation is going to error, we would transpile from:

import { hbs } from 'ember-cli-htmlbars';

const layout = hbs('some bad template', { insertRuntimeErrors: true });

And assuming that this compilation would normally throw an error with the message "ZOMG don't do this", you would have the following compilation output:

const layout = function() {
  throw new Error("ZOMG don't do this');
}();

@rwjblue rwjblue force-pushed the add-ability-to-insertRuntimeErrors branch from 6a7e0ce to bdbe63a Compare May 6, 2020 00:16
@rwjblue rwjblue force-pushed the add-ability-to-insertRuntimeErrors branch from bdbe63a to 392298d Compare May 6, 2020 00:25
@rwjblue rwjblue requested a review from chancancode May 6, 2020 00:31
try {
precompileResult = precompile(template, options);
} catch (error) {
return runtimeErrorIIFE({ ERROR_MESSAGE: error.message });
Copy link
Contributor

Choose a reason for hiding this comment

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

I assume babel is taking care of escaping for us, is that right?

Copy link
Member Author

Choose a reason for hiding this comment

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

not sure, will test

Copy link
Member Author

Choose a reason for hiding this comment

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

Ya, the error.message itself is already a string, and any valid string will work (including any escaping needed internally).

@rwjblue rwjblue merged commit e3bb3db into master May 6, 2020
@rwjblue rwjblue deleted the add-ability-to-insertRuntimeErrors branch May 6, 2020 00:52
@ef4
Copy link

ef4 commented Nov 29, 2020

Having just noticed this, I want to point out that it has stronger compatibility concerns than may be obvious.

v2 addons don't get to bring their own version of ember-cli-htmlbars along. Instead, the hbs macro is considered an always-available language extension. So we really need to never change it in a backward-incompatible way.

This particular change is backward-compatible, so it's not a problem, but it does mean we are committing to supporting this option forever. You can't just rev the major version of ember-cli-htmlbars to change it, because addons won't have any control over the version of ember-cli-htmlbars in use.

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

Successfully merging this pull request may close these issues.

3 participants