fix(compiler-cli): Fix swallowed Error messages (#20846)
This commit fixes a bug in which non-formatted errors are silently dropped. Internal issue: b/67739418 PR Close #20846
This commit is contained in:
parent
c2dbc55f11
commit
073f485c72
@ -869,17 +869,21 @@ function syntaxErrorToDiagnostics(error: Error): Diagnostic[] {
|
|||||||
source: SOURCE,
|
source: SOURCE,
|
||||||
code: DEFAULT_ERROR_CODE
|
code: DEFAULT_ERROR_CODE
|
||||||
}));
|
}));
|
||||||
} else {
|
} else if (isFormattedError(error)) {
|
||||||
if (isFormattedError(error)) {
|
return [{
|
||||||
return [{
|
messageText: error.message,
|
||||||
messageText: error.message,
|
chain: error.chain && diagnosticChainFromFormattedDiagnosticChain(error.chain),
|
||||||
chain: error.chain && diagnosticChainFromFormattedDiagnosticChain(error.chain),
|
category: ts.DiagnosticCategory.Error,
|
||||||
category: ts.DiagnosticCategory.Error,
|
source: SOURCE,
|
||||||
source: SOURCE,
|
code: DEFAULT_ERROR_CODE,
|
||||||
code: DEFAULT_ERROR_CODE,
|
position: error.position
|
||||||
position: error.position
|
}];
|
||||||
}];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return [];
|
// Produce a Diagnostic anyway since we know for sure `error` is a SyntaxError
|
||||||
}
|
return [{
|
||||||
|
messageText: error.message,
|
||||||
|
category: ts.DiagnosticCategory.Error,
|
||||||
|
code: DEFAULT_ERROR_CODE,
|
||||||
|
source: SOURCE,
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
@ -948,6 +948,35 @@ describe('ng program', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should include non-formatted errors (e.g. invalid templateUrl)', () => {
|
||||||
|
testSupport.write('src/index.ts', `
|
||||||
|
import {Component, NgModule} from '@angular/core';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'my-component',
|
||||||
|
templateUrl: 'template.html', // invalid template url
|
||||||
|
})
|
||||||
|
export class MyComponent {}
|
||||||
|
|
||||||
|
@NgModule({
|
||||||
|
declarations: [MyComponent]
|
||||||
|
})
|
||||||
|
export class MyModule {}
|
||||||
|
`);
|
||||||
|
|
||||||
|
const options = testSupport.createCompilerOptions();
|
||||||
|
const host = ng.createCompilerHost({options});
|
||||||
|
const program = ng.createProgram({
|
||||||
|
rootNames: [path.resolve(testSupport.basePath, 'src/index.ts')],
|
||||||
|
options,
|
||||||
|
host,
|
||||||
|
});
|
||||||
|
|
||||||
|
const structuralErrors = program.getNgStructuralDiagnostics();
|
||||||
|
expect(structuralErrors.length).toBe(1);
|
||||||
|
expect(structuralErrors[0].messageText).toContain('Couldn\'t resolve resource template.html');
|
||||||
|
});
|
||||||
|
|
||||||
it('should be able report structural errors with noResolve:true and generateCodeForLibraries:false ' +
|
it('should be able report structural errors with noResolve:true and generateCodeForLibraries:false ' +
|
||||||
'even if getSourceFile throws for non existent files',
|
'even if getSourceFile throws for non existent files',
|
||||||
() => {
|
() => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user