From 1e663f08764041d5b29b5129c3d1f7c9813a2379 Mon Sep 17 00:00:00 2001 From: Peter Evans <18365890+peter-evans@users.noreply.github.com> Date: Fri, 21 Oct 2022 15:19:19 +0900 Subject: [PATCH] fix: replace use of any type --- dist/index.js | 7 ++++++- src/main.ts | 9 +++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/dist/index.js b/dist/index.js index f27c8df..11b0695 100644 --- a/dist/index.js +++ b/dist/index.js @@ -92,6 +92,11 @@ function findComment(inputs) { return undefined; }); } +function getErrorMessage(error) { + if (error instanceof Error) + return error.message; + return String(error); +} function run() { return __awaiter(this, void 0, void 0, function* () { try { @@ -118,7 +123,7 @@ function run() { } catch (error) { core.debug((0, util_1.inspect)(error)); - core.setFailed(error.message); + core.setFailed(getErrorMessage(error)); } }); } diff --git a/src/main.ts b/src/main.ts index 704ad30..e8e6c4c 100644 --- a/src/main.ts +++ b/src/main.ts @@ -66,6 +66,11 @@ async function findComment(inputs: Inputs): Promise { return undefined } +function getErrorMessage(error: unknown) { + if (error instanceof Error) return error.message + return String(error) +} + async function run(): Promise { try { const inputs: Inputs = { @@ -89,9 +94,9 @@ async function run(): Promise { core.setOutput('comment-body', '') core.setOutput('comment-author', '') } - } catch (error: any) { + } catch (error) { core.debug(inspect(error)) - core.setFailed(error.message) + core.setFailed(getErrorMessage(error)) } }