From 5d7223261bcae31f3583659e3637ca9a54b909d0 Mon Sep 17 00:00:00 2001 From: panticmilos Date: Tue, 14 Jun 2022 12:05:49 +0200 Subject: [PATCH] add restore cache error handling --- dist/cache-save/index.js | 16 +++++++++++-- dist/setup/index.js | 16 +++++++++++-- src/cache-distributions/cache-distributor.ts | 24 +++++++++++++++----- 3 files changed, 46 insertions(+), 10 deletions(-) diff --git a/dist/cache-save/index.js b/dist/cache-save/index.js index 35cedd90..3689f58f 100644 --- a/dist/cache-save/index.js +++ b/dist/cache-save/index.js @@ -57529,8 +57529,20 @@ class CacheDistributor { const cachePath = yield this.getCacheGlobalDirectories(); core.saveState(State.CACHE_PATHS, cachePath); core.saveState(State.STATE_CACHE_PRIMARY_KEY, primaryKey); - const matchedKey = yield cache.restoreCache(cachePath, primaryKey, restoreKey); - this.handleMatchResult(matchedKey, primaryKey); + try { + const matchedKey = yield cache.restoreCache(cachePath, primaryKey, restoreKey); + this.handleMatchResult(matchedKey, primaryKey); + } + catch (error) { + const typedError = error; + if (typedError.name === cache.ValidationError.name) { + throw error; + } + else { + core.warning(typedError.message); + core.setOutput('cache-hit', false); + } + } }); } handleMatchResult(matchedKey, primaryKey) { diff --git a/dist/setup/index.js b/dist/setup/index.js index 2b2504b0..2a64dcb1 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -63600,8 +63600,20 @@ class CacheDistributor { const cachePath = yield this.getCacheGlobalDirectories(); core.saveState(State.CACHE_PATHS, cachePath); core.saveState(State.STATE_CACHE_PRIMARY_KEY, primaryKey); - const matchedKey = yield cache.restoreCache(cachePath, primaryKey, restoreKey); - this.handleMatchResult(matchedKey, primaryKey); + try { + const matchedKey = yield cache.restoreCache(cachePath, primaryKey, restoreKey); + this.handleMatchResult(matchedKey, primaryKey); + } + catch (error) { + const typedError = error; + if (typedError.name === cache.ValidationError.name) { + throw error; + } + else { + core.warning(typedError.message); + core.setOutput('cache-hit', false); + } + } }); } handleMatchResult(matchedKey, primaryKey) { diff --git a/src/cache-distributions/cache-distributor.ts b/src/cache-distributions/cache-distributor.ts index f24c78da..c1f5b769 100644 --- a/src/cache-distributions/cache-distributor.ts +++ b/src/cache-distributions/cache-distributor.ts @@ -35,13 +35,25 @@ abstract class CacheDistributor { core.saveState(State.CACHE_PATHS, cachePath); core.saveState(State.STATE_CACHE_PRIMARY_KEY, primaryKey); - const matchedKey = await cache.restoreCache( - cachePath, - primaryKey, - restoreKey - ); + try { + const matchedKey = await cache.restoreCache( + cachePath, + primaryKey, + restoreKey + ); + + this.handleMatchResult(matchedKey, primaryKey); + } catch(error) { + const typedError = error as Error; + if (typedError.name === cache.ValidationError.name) { + throw error; + } else { + core.warning(typedError.message); + core.setOutput('cache-hit', false); + } + } + - this.handleMatchResult(matchedKey, primaryKey); } public handleMatchResult(matchedKey: string | undefined, primaryKey: string) {