Skip to content

Commit e7ea1aa

Browse files
committed
Narrow caught exceptions
The update to 4.4.2 brings increased type strictness. Previously, exceptions were used in some catch blocks based on an assumption of their type. But exceptions can have any type and that now results in errors (TS2345, TS2571). This is fixed by narrowing the exceptions to the expected type before using them as such.
1 parent 3753be4 commit e7ea1aa

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

dist/index.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,9 @@ function downloadRelease(version) {
158158
downloadPath = yield tc.downloadTool(downloadUrl);
159159
}
160160
catch (error) {
161-
core.debug(error);
161+
if (typeof error === "string" || error instanceof Error) {
162+
core.debug(error.toString());
163+
}
162164
throw new Error(`Failed to download version ${version}: ${error}`);
163165
}
164166
// Extract
@@ -255,7 +257,12 @@ function run() {
255257
yield installer.getTask(version, repoToken);
256258
}
257259
catch (error) {
258-
core.setFailed(error.message);
260+
if (error instanceof Error) {
261+
core.setFailed(error.message);
262+
}
263+
else {
264+
throw error;
265+
}
259266
}
260267
});
261268
}

src/installer.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,9 @@ async function downloadRelease(version: string): Promise<string> {
155155
try {
156156
downloadPath = await tc.downloadTool(downloadUrl);
157157
} catch (error) {
158-
core.debug(error);
158+
if (typeof error === "string" || error instanceof Error) {
159+
core.debug(error.toString());
160+
}
159161
throw new Error(`Failed to download version ${version}: ${error}`);
160162
}
161163

src/main.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ async function run() {
2020

2121
await installer.getTask(version, repoToken);
2222
} catch (error) {
23-
core.setFailed(error.message);
23+
if (error instanceof Error) {
24+
core.setFailed(error.message);
25+
} else {
26+
throw error;
27+
}
2428
}
2529
}
2630

0 commit comments

Comments
 (0)