Skip to content

Commit 3dced54

Browse files
clydinmgechev
authored andcommitted
feat(@angular/cli): log unhandled exceptions
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.
1 parent fd90f10 commit 3dced54

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

packages/angular/cli/lib/cli/index.ts

+23-3
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,30 @@ export default async function(options: { testing?: boolean, cliArgs: string[] })
6161
return 0;
6262
} catch (err) {
6363
if (err instanceof Error) {
64-
logger.fatal(err.message);
65-
if (err.stack) {
66-
logger.fatal(err.stack);
64+
try {
65+
const fs = await import('fs');
66+
const os = await import('os');
67+
const tempDirectory = fs.mkdtempSync(fs.realpathSync(os.tmpdir()) + '/' + 'ng-');
68+
const logPath = tempDirectory + '/angular-errors.log';
69+
fs.appendFileSync(logPath, '[error] ' + (err.stack || err));
70+
71+
logger.fatal(
72+
`An unhandled exception occurred: ${err.message}\n` +
73+
`See "${logPath}" for further details.\n\n` +
74+
'Please report with the contents of the log file at ' +
75+
'https://github.com/angular/angular-cli/issues/new?template=1-bug-report.md',
76+
);
77+
} catch (e) {
78+
logger.fatal(
79+
`An unhandled exception occurred: ${err.message}\n` +
80+
`Fatal error writing debug log file: ${e.message}`,
81+
);
82+
if (err.stack) {
83+
logger.fatal(err.stack);
84+
}
6785
}
86+
87+
return 127;
6888
} else if (typeof err === 'string') {
6989
logger.fatal(err);
7090
} else if (typeof err === 'number') {

0 commit comments

Comments
 (0)