Skip to content

Commit 2636262

Browse files
clydinalan-agius4
authored andcommitted
refactor(@ngtools/webpack): assert catch clause variable type before usage
Prepares the `@ngtools/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 9b1a36a commit 2636262

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

packages/ngtools/webpack/src/resource_loader.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9+
import assert from 'assert';
910
import * as path from 'path';
1011
import * as vm from 'vm';
1112
import type { Asset, Compilation } from 'webpack';
@@ -115,6 +116,7 @@ export class WebpackResourceLoader {
115116
const {
116117
EntryPlugin,
117118
NormalModule,
119+
WebpackError,
118120
library,
119121
node,
120122
sources,
@@ -208,8 +210,9 @@ export class WebpackResourceLoader {
208210
compilation.assets[outputFilePath] = new sources.RawSource(output);
209211
}
210212
} catch (error) {
213+
assert(error instanceof Error, 'catch clause variable is not an Error instance');
211214
// Use compilation errors, as otherwise webpack will choke
212-
compilation.errors.push(error);
215+
compilation.errors.push(new WebpackError(error.message));
213216
}
214217
});
215218
},

0 commit comments

Comments
 (0)