From 52f0597e2f4f6ce88bf7f975cfc5aa5e4c996012 Mon Sep 17 00:00:00 2001 From: Peter Evans <18365890+peter-evans@users.noreply.github.com> Date: Fri, 21 Oct 2022 15:01:02 +0900 Subject: [PATCH] Replace use of any type --- dist/index.js | 10 ++++++++-- src/main.ts | 4 ++-- src/utils.ts | 5 +++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/dist/index.js b/dist/index.js index 2a84e29..07d0455 100644 --- a/dist/index.js +++ b/dist/index.js @@ -117,7 +117,7 @@ function run() { } catch (error) { core.debug((0, util_1.inspect)(error)); - core.setFailed(error.message); + core.setFailed(utils.getErrorMessage(error)); } }); } @@ -151,7 +151,7 @@ var __importStar = (this && this.__importStar) || function (mod) { return result; }; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.getStringAsArray = exports.getInputAsArray = void 0; +exports.getErrorMessage = exports.getStringAsArray = exports.getInputAsArray = void 0; const core = __importStar(__nccwpck_require__(2186)); function getInputAsArray(name, options) { return getStringAsArray(core.getInput(name, options)); @@ -164,6 +164,12 @@ function getStringAsArray(str) { .filter(x => x !== ''); } exports.getStringAsArray = getStringAsArray; +function getErrorMessage(error) { + if (error instanceof Error) + return error.message; + return String(error); +} +exports.getErrorMessage = getErrorMessage; /***/ }), diff --git a/src/main.ts b/src/main.ts index 1ea644b..4c5bb7f 100644 --- a/src/main.ts +++ b/src/main.ts @@ -81,9 +81,9 @@ async function run(): Promise { } else { core.info(`File not found at path '${inputs.contentFilepath}'`) } - } catch (error: any) { + } catch (error) { core.debug(inspect(error)) - core.setFailed(error.message) + core.setFailed(utils.getErrorMessage(error)) } } diff --git a/src/utils.ts b/src/utils.ts index 59b21e7..52dc897 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -13,3 +13,8 @@ export function getStringAsArray(str: string): string[] { .map(s => s.trim()) .filter(x => x !== '') } + +export function getErrorMessage(error: unknown) { + if (error instanceof Error) return error.message + return String(error) +}