Skip to content

Commit 93ecf41

Browse files
committed
Narrow caught exceptions
The update from TypeScript 3.9.7 to 4.5.4 brings increased type strictness (introduced in 4.4). 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 7c3b7b2 commit 93ecf41

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/installer.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ async function downloadRelease(version: string): Promise<string> {
6767
const token: string = core.getInput("token", { required: true });
6868
downloadPath = await tc.downloadTool(downloadUrl, undefined, token);
6969
} catch (error) {
70-
core.debug(error);
70+
if (typeof error === "string" || error instanceof Error) {
71+
core.debug(error.toString());
72+
}
7173
throw `Failed to download version ${version}: ${error}`;
7274
}
7375

src/main.ts

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

5959
await exec.exec(toolPath, execArgs, options);
6060
} catch (error) {
61-
core.setFailed(error.message);
61+
if (error instanceof Error) {
62+
core.setFailed(error.message);
63+
} else {
64+
throw error;
65+
}
6266
}
6367
}
6468

0 commit comments

Comments
 (0)