From f2d5621efc7436e834db356e3f05a1d839f9344c Mon Sep 17 00:00:00 2001 From: Deepak Dahiya <59823596+t-dedah@users.noreply.github.com> Date: Wed, 4 May 2022 12:32:55 +0000 Subject: [PATCH] Turning error from any to unknown --- src/restore.ts | 16 +++++++++++----- src/save.ts | 15 ++++++++------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/restore.ts b/src/restore.ts index e95d09f..220733c 100644 --- a/src/restore.ts +++ b/src/restore.ts @@ -4,6 +4,11 @@ import * as core from "@actions/core"; import { Events, Inputs, State } from "./constants"; import * as utils from "./utils/actionUtils"; +interface RestoreError { + name: string; + message: string; +} + async function run(): Promise { try { if (!utils.isCacheFeatureAvailable()) { @@ -52,16 +57,17 @@ async function run(): Promise { utils.setCacheHitOutput(isExactKeyMatch); core.info(`Cache restored from key: ${cacheKey}`); - } catch (error: any) { - if (error.name === cache.ValidationError.name) { + } catch (error: unknown) { + const typedError = error as Error; + if (typedError.name === cache.ValidationError.name) { throw error; } else { - utils.logWarning(error.message); + utils.logWarning(typedError.message); utils.setCacheHitOutput(false); } } - } catch (error: any) { - core.setFailed(error.message); + } catch (error: unknown) { + core.setFailed((error as Error ).message); } } diff --git a/src/save.ts b/src/save.ts index e3e7751..7b333fb 100644 --- a/src/save.ts +++ b/src/save.ts @@ -49,17 +49,18 @@ async function run(): Promise { uploadChunkSize: utils.getInputAsInt(Inputs.UploadChunkSize) }); core.info(`Cache saved with key: ${primaryKey}`); - } catch (error: any) { - if (error.name === cache.ValidationError.name) { + } catch (error: unknown) { + const typedError = error as Error; + if (typedError.name === cache.ValidationError.name) { throw error; - } else if (error.name === cache.ReserveCacheError.name) { - core.info(error.message); + } else if (typedError.name === cache.ReserveCacheError.name) { + core.info(typedError.message); } else { - utils.logWarning(error.message); + utils.logWarning(typedError.message); } } - } catch (error: any) { - utils.logWarning(error.message); + } catch (error: unknown) { + utils.logWarning((error as Error).message); } }