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

[BUGFIX release] Fix Ember.Error inheritance #15522

Closed
wants to merge 2 commits into from
Closed

Conversation

stefanpenner
Copy link
Member

@stefanpenner stefanpenner commented Jul 17, 2017

As pointed out by @schuay #15516 our error constructor essentially calls super twice. The reasons seems to have been an error in ExtendableBuiltin constructor, which did not return its apply call. I can’t seem to find the issue ExtendBuiltin is working around. I suspect we can simply remove it

cc @schuay

Copy link
Contributor

@chadhietala chadhietala left a comment

Choose a reason for hiding this comment

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

I feel like this didn't work for some reason at some point, but if CI passes I'm 👍 .

@stefanpenner
Copy link
Member Author

@chadhietala I tested some cases manually, which seemed to work. Could you give it a try as well?


let error = Error.call(this, message);
this.stack = error.stack;
Copy link
Contributor

Choose a reason for hiding this comment

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

if super() is called is this still needed?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think so in transpiled land

As pointed out by @schuay #15516 our error constructor essentially calls super twice. The reasons seems to have been an error in ExtendableBuiltin constructor, which did not return its `apply` call. I can’t seem to find the issue ExtendBuiltin is working around. I suspect we can simply remove it
return new EmberError(message);
}
export default EmberError;
function EmberError(message, code) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Dumb question, but why make this a function instead of using the fancy ES6 classes?

Copy link
Member Author

Choose a reason for hiding this comment

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

EmberError unfortunately supports being invoked without using new. This ends up being a less hacky solution. We should deprecate that, so we can eventually switch over entirely though.

Copy link
Contributor

Choose a reason for hiding this comment

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

Cool! Thank you for taking a moment to respond to my question.

@locks
Copy link
Contributor

locks commented Jul 18, 2017

@stefanpenner IE is not happy in saucelabs :\

export default EmberError;
function EmberError(message, code) {
if (this instanceof EmberError) {
let error = Error.call(this, message, code);
Copy link

Choose a reason for hiding this comment

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

FYI: In V8, using super() would give you the benefit of omitting all frames up to and including the EmberError constructor (which is what I believe Error.captureStackTrace was used for). ES6 Error subclasses are basically the better Error.captureStackTrace. Copying error properties below would also be unnecessary.

I'm not sure how other browsers behave though.

Copy link
Member Author

Choose a reason for hiding this comment

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

We aren't actually using real super (getting transpiled) also we still support an unfortunate scenario calling the constructor without new. Which ES6 classes don't support. We will need to deprecate that first, then remove in the future.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll open another PR that deprecated the call constructor behavior so by the best LTS we can drop

@stefanpenner
Copy link
Member Author

stefanpenner commented Jul 18, 2017

test failure seems like one of the spurious sauce labs issues... restarting that job

@Serabe
Copy link
Member

Serabe commented Sep 3, 2017

@stefanpenner this is failing for real (restarted to get the screenshots).

0005screenshot

@Turbo87
Copy link
Member

Turbo87 commented Dec 19, 2018

closing this, as #17216 made it obsolete

@Turbo87 Turbo87 closed this Dec 19, 2018
@Turbo87 Turbo87 deleted the fix-error-ctor branch December 19, 2018 16:08
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

9 participants