feat(ivy): improve stacktrace for R3Injector errors (#28207)

Improve the stacktrace for `R3Injector` errors by adding the source component (or module) that tried to inject the missing provider, as well as the name of the injector which triggered the error (`R3Injector`).

e.g.:
```
R3InjectorError(SomeModule)[car -> SportsCar]:
    NullInjectorError: No provider for SportsCar!
```

FW-807 #resolve
FW-875 #resolve

PR Close #28207
This commit is contained in:
Olivier Combe
2019-01-17 18:48:39 +01:00
committed by Matias Niemelä
parent 7219639ff3
commit 728fe69625
10 changed files with 230 additions and 77 deletions

View File

@ -734,8 +734,11 @@ function declareTests(config?: {useJit: boolean}) {
it('should throw when the aliased provider does not exist', () => {
const injector = createInjector([{provide: 'car', useExisting: SportsCar}]);
const e = `NullInjectorError: No provider for ${stringify(SportsCar)}!`;
expect(() => injector.get('car')).toThrowError(e);
let errorMsg = `NullInjectorError: No provider for ${stringify(SportsCar)}!`;
if (ivyEnabled) {
errorMsg = `R3InjectorError(SomeModule)[car -> SportsCar]: \n ` + errorMsg;
}
expect(() => injector.get('car')).toThrowError(errorMsg);
});
it('should handle forwardRef in useExisting', () => {
@ -930,8 +933,11 @@ function declareTests(config?: {useJit: boolean}) {
it('should throw when no provider defined', () => {
const injector = createInjector([]);
expect(() => injector.get('NonExisting'))
.toThrowError('NullInjectorError: No provider for NonExisting!');
let errorMsg = 'NullInjectorError: No provider for NonExisting!';
if (ivyEnabled) {
errorMsg = `R3InjectorError(SomeModule)[NonExisting]: \n ` + errorMsg;
}
expect(() => injector.get('NonExisting')).toThrowError(errorMsg);
});
it('should throw when trying to instantiate a cyclic dependency', () => {