Skip to content

Commit 3c4ca3f

Browse files
clydinalan-agius4
authored andcommitted
refactor(@angular-devkit/build-webpack): assert catch clause variable type before usage
Prepares the `@angular-devkit/build-webpack` 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 6a3c0b0 commit 3c4ca3f

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

packages/angular_devkit/build_webpack/src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export async function getWebpackConfig(configPath: string): Promise<Configuratio
9090
try {
9191
return require(configPath);
9292
} catch (e) {
93-
if (e.code === 'ERR_REQUIRE_ESM') {
93+
if ((e as NodeJS.ErrnoException).code === 'ERR_REQUIRE_ESM') {
9494
// Load the ESM configuration file using the TypeScript dynamic import workaround.
9595
// Once TypeScript provides support for keeping the dynamic import this workaround can be
9696
// changed to a direct dynamic import.

packages/angular_devkit/build_webpack/src/webpack/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export function runWebpack(
105105
} catch (err) {
106106
if (err) {
107107
context.logger.error(
108-
`\nAn error occurred during the build:\n${(err && err.stack) || err}`,
108+
`\nAn error occurred during the build:\n${err instanceof Error ? err.stack : err}`,
109109
);
110110
}
111111
throw err;

0 commit comments

Comments
 (0)