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 LTS] Improve error for owner methods called after destroy #20385

Merged
merged 1 commit into from
Feb 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/@ember/-internals/container/lib/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export default class Container {
options?: RegisterOptions
): InternalFactory<object> | object | undefined {
if (this.isDestroyed) {
throw new Error(`Cannot call \`.lookup\` after the owner has been destroyed`);
throw new Error(`Cannot call \`.lookup('${fullName}')\` after the owner has been destroyed`);
}
assert('fullName must be a proper full name', this.registry.isValidFullName(fullName));
return lookup(this, this.registry.normalize(fullName), options);
Expand Down Expand Up @@ -217,7 +217,9 @@ export default class Container {
*/
factoryFor(fullName: FullName): InternalFactoryManager<object> | undefined {
if (this.isDestroyed) {
throw new Error(`Cannot call \`.factoryFor\` after the owner has been destroyed`);
throw new Error(
`Cannot call \`.factoryFor('${fullName}')\` after the owner has been destroyed`
);
}
let normalizedName = this.registry.normalize(fullName);

Expand Down
4 changes: 2 additions & 2 deletions packages/@ember/-internals/container/tests/container_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ moduleFor(

assert.throws(() => {
container.lookup('service:foo');
}, /Cannot call `.lookup` after the owner has been destroyed/);
}, "Cannot call `.lookup('service:foo')` after the owner has been destroyed");
}

[`@test assert when calling factoryFor after destroy on a container`](assert) {
Expand All @@ -626,7 +626,7 @@ moduleFor(

assert.throws(() => {
container.factoryFor('service:foo');
}, /Cannot call `.factoryFor` after the owner has been destroyed/);
}, "Cannot call `.factoryFor('service:foo')` after the owner has been destroyed");
}

// this is skipped until templates and the glimmer environment do not require `OWNER` to be
Expand Down