Skip to content

Commit 1b9880c

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

File tree

3 files changed

+6
-9
lines changed

3 files changed

+6
-9
lines changed

packages/angular_devkit/architect/node/node-modules-architect-host.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ async function getBuilder(builderPath: string): Promise<any> {
245245
try {
246246
return require(builderPath);
247247
} catch (e) {
248-
if (e.code === 'ERR_REQUIRE_ESM') {
248+
if ((e as NodeJS.ErrnoException).code === 'ERR_REQUIRE_ESM') {
249249
// Load the ESM configuration file using the TypeScript dynamic import workaround.
250250
// Once TypeScript provides support for keeping the dynamic import this workaround can be
251251
// changed to a direct dynamic import.

packages/angular_devkit/architect/src/index_spec.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,10 @@ describe('architect', () => {
136136
await run.stop();
137137
});
138138

139-
it(`errors when target configuration doesn't exists`, async () => {
140-
try {
141-
await architect.scheduleBuilder('test:test:invalid', {});
142-
throw new Error('should have thrown');
143-
} catch (err) {
144-
expect(err.message).toContain('Job name "test:test:invalid" does not exist.');
145-
}
139+
it(`errors when target configuration does not exist`, async () => {
140+
await expectAsync(architect.scheduleBuilder('test:test:invalid', {})).toBeRejectedWithError(
141+
'Job name "test:test:invalid" does not exist.',
142+
);
146143
});
147144

148145
it('errors when builder cannot be resolved', async () => {

packages/angular_devkit/architect_cli/bin/architect.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ async function _executeTarget(
179179
logs.forEach((l) => parentLogger.next(l));
180180
181181
parentLogger.fatal('Exception:');
182-
parentLogger.fatal(err.stack);
182+
parentLogger.fatal((err instanceof Error && err.stack) || `${err}`);
183183
184184
return 2;
185185
}

0 commit comments

Comments
 (0)