Skip to content

Commit

Permalink
Narrow caught exceptions
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
per1234 committed Sep 1, 2021
1 parent 3753be4 commit e7ea1aa
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
11 changes: 9 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,9 @@ function downloadRelease(version) {
downloadPath = yield tc.downloadTool(downloadUrl);
}
catch (error) {
core.debug(error);
if (typeof error === "string" || error instanceof Error) {
core.debug(error.toString());
}
throw new Error(`Failed to download version ${version}: ${error}`);
}
// Extract
Expand Down Expand Up @@ -255,7 +257,12 @@ function run() {
yield installer.getTask(version, repoToken);
}
catch (error) {
core.setFailed(error.message);
if (error instanceof Error) {
core.setFailed(error.message);
}
else {
throw error;
}
}
});
}
Expand Down
4 changes: 3 additions & 1 deletion src/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ async function downloadRelease(version: string): Promise<string> {
try {
downloadPath = await tc.downloadTool(downloadUrl);
} catch (error) {
core.debug(error);
if (typeof error === "string" || error instanceof Error) {
core.debug(error.toString());
}
throw new Error(`Failed to download version ${version}: ${error}`);
}

Expand Down
6 changes: 5 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ async function run() {

await installer.getTask(version, repoToken);
} catch (error) {
core.setFailed(error.message);
if (error instanceof Error) {
core.setFailed(error.message);
} else {
throw error;
}
}
}

Expand Down

0 comments on commit e7ea1aa

Please sign in to comment.