Skip to content

Commit 6a3c0b0

Browse files
clydinalan-agius4
authored andcommitted
refactor(@angular-devkit/schematics-cli): assert catch clause variable type before usage
Prepares the `@angular-devkit/schematics-cli` package for the eventual change of enabling the TypeScript `useUnknownInCatchVariables` option. This option provides additional code safety by ensuring that the catch clause variable is the proper type before attempting to access its properties. Similar changes will be needed in the other packages in the repository prior to enabling `useUnknownInCatchVariables`.
1 parent cb9ee24 commit 6a3c0b0

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

packages/angular_devkit/schematics_cli/bin/schematics.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function _listSchematics(workflow: NodeWorkflow, collectionName: string, logger:
5757
const collection = workflow.engine.createCollection(collectionName);
5858
logger.info(collection.listSchematicNames().join('\n'));
5959
} catch (error) {
60-
logger.fatal(error.message);
60+
logger.fatal(error instanceof Error ? error.message : `${error}`);
6161

6262
return 1;
6363
}
@@ -285,10 +285,10 @@ export async function main({
285285
if (err instanceof UnsuccessfulWorkflowExecution) {
286286
// "See above" because we already printed the error.
287287
logger.fatal('The Schematic workflow failed. See above.');
288-
} else if (debug) {
288+
} else if (debug && err instanceof Error) {
289289
logger.fatal(`An error occured:\n${err.stack}`);
290290
} else {
291-
logger.fatal(`Error: ${err.message}`);
291+
logger.fatal(`Error: ${err instanceof Error ? err.message : err}`);
292292
}
293293

294294
return 1;

0 commit comments

Comments
 (0)