fix(core): report errors for missing di tokens correctly (#11209)
This commit is contained in:
parent
6ea5b05e7c
commit
cc89ef6c8c
|
@ -68,8 +68,6 @@ export class AbstractProviderError extends BaseError {
|
||||||
this.keys.push(key);
|
this.keys.push(key);
|
||||||
this.message = this.constructResolvingMessage(this.keys);
|
this.message = this.constructResolvingMessage(this.keys);
|
||||||
}
|
}
|
||||||
|
|
||||||
get context() { return this.injectors[this.injectors.length - 1].debugContext(); }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -174,8 +172,6 @@ export class InstantiationError extends WrappedError {
|
||||||
}
|
}
|
||||||
|
|
||||||
get causeKey(): ReflectiveKey { return this.keys[0]; }
|
get causeKey(): ReflectiveKey { return this.keys[0]; }
|
||||||
|
|
||||||
get context() { return this.injectors[this.injectors.length - 1].debugContext(); }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -473,12 +473,6 @@ export abstract class ReflectiveInjector implements Injector {
|
||||||
*/
|
*/
|
||||||
get parent(): Injector { return unimplemented(); }
|
get parent(): Injector { return unimplemented(); }
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @internal
|
|
||||||
*/
|
|
||||||
debugContext(): any { return null; }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolves an array of providers and creates a child injector from those providers.
|
* Resolves an array of providers and creates a child injector from those providers.
|
||||||
*
|
*
|
||||||
|
@ -603,19 +597,12 @@ export class ReflectiveInjector_ implements ReflectiveInjector {
|
||||||
/**
|
/**
|
||||||
* Private
|
* Private
|
||||||
*/
|
*/
|
||||||
constructor(
|
constructor(_proto: any /* ProtoInjector */, _parent: Injector = null) {
|
||||||
_proto: any /* ProtoInjector */, _parent: Injector = null,
|
|
||||||
private _debugContext: Function = null) {
|
|
||||||
this._proto = _proto;
|
this._proto = _proto;
|
||||||
this._parent = _parent;
|
this._parent = _parent;
|
||||||
this._strategy = _proto._strategy.createInjectorStrategy(this);
|
this._strategy = _proto._strategy.createInjectorStrategy(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @internal
|
|
||||||
*/
|
|
||||||
debugContext(): any { return this._debugContext(); }
|
|
||||||
|
|
||||||
get(token: any, notFoundValue: any = THROW_IF_NOT_FOUND): any {
|
get(token: any, notFoundValue: any = THROW_IF_NOT_FOUND): any {
|
||||||
return this._getByKey(ReflectiveKey.get(token), null, null, notFoundValue);
|
return this._getByKey(ReflectiveKey.get(token), null, null, notFoundValue);
|
||||||
}
|
}
|
||||||
|
|
|
@ -336,25 +336,6 @@ export function main() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should provide context when throwing an exception ', () => {
|
|
||||||
var engineProvider =
|
|
||||||
ReflectiveInjector.resolve([{provide: Engine, useClass: BrokenEngine}])[0];
|
|
||||||
var protoParent = new ReflectiveProtoInjector([engineProvider]);
|
|
||||||
|
|
||||||
var carProvider = ReflectiveInjector.resolve([Car])[0];
|
|
||||||
var protoChild = new ReflectiveProtoInjector([carProvider]);
|
|
||||||
|
|
||||||
var parent = new ReflectiveInjector_(protoParent, null, () => 'parentContext');
|
|
||||||
var child = new ReflectiveInjector_(protoChild, parent, () => 'childContext');
|
|
||||||
|
|
||||||
try {
|
|
||||||
child.get(Car);
|
|
||||||
throw 'Must throw';
|
|
||||||
} catch (e) {
|
|
||||||
expect(e.context).toEqual('childContext');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should instantiate an object after a failed attempt', () => {
|
it('should instantiate an object after a failed attempt', () => {
|
||||||
var isBroken = true;
|
var isBroken = true;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue