Skip to content

Commit

Permalink
feat(@angular/cli): log unhandled exceptions
Browse files Browse the repository at this point in the history
Whenever an unhandled exception during command processing occurs, the message and stack trace will be saved to a debug log located in a temporary directory.  The user will be informed of the log location as well as the exception message and instructions to file a bug report at the GitHub repository.
  • Loading branch information
clydin authored and mgechev committed Jun 17, 2019
1 parent fd90f10 commit 3dced54
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions packages/angular/cli/lib/cli/index.ts
Expand Up @@ -61,10 +61,30 @@ export default async function(options: { testing?: boolean, cliArgs: string[] })
return 0;
} catch (err) {
if (err instanceof Error) {
logger.fatal(err.message);
if (err.stack) {
logger.fatal(err.stack);
try {
const fs = await import('fs');
const os = await import('os');
const tempDirectory = fs.mkdtempSync(fs.realpathSync(os.tmpdir()) + '/' + 'ng-');
const logPath = tempDirectory + '/angular-errors.log';
fs.appendFileSync(logPath, '[error] ' + (err.stack || err));

logger.fatal(
`An unhandled exception occurred: ${err.message}\n` +
`See "${logPath}" for further details.\n\n` +
'Please report with the contents of the log file at ' +
'https://github.com/angular/angular-cli/issues/new?template=1-bug-report.md',
);
} catch (e) {
logger.fatal(
`An unhandled exception occurred: ${err.message}\n` +
`Fatal error writing debug log file: ${e.message}`,
);
if (err.stack) {
logger.fatal(err.stack);
}
}

return 127;
} else if (typeof err === 'string') {
logger.fatal(err);
} else if (typeof err === 'number') {
Expand Down

0 comments on commit 3dced54

Please sign in to comment.