add restore cache error handling

This commit is contained in:
panticmilos 2022-06-14 12:05:49 +02:00
parent 7e4abae443
commit 5d7223261b
3 changed files with 46 additions and 10 deletions

View file

@ -57529,8 +57529,20 @@ class CacheDistributor {
const cachePath = yield this.getCacheGlobalDirectories(); const cachePath = yield this.getCacheGlobalDirectories();
core.saveState(State.CACHE_PATHS, cachePath); core.saveState(State.CACHE_PATHS, cachePath);
core.saveState(State.STATE_CACHE_PRIMARY_KEY, primaryKey); core.saveState(State.STATE_CACHE_PRIMARY_KEY, primaryKey);
try {
const matchedKey = yield cache.restoreCache(cachePath, primaryKey, restoreKey); const matchedKey = yield cache.restoreCache(cachePath, primaryKey, restoreKey);
this.handleMatchResult(matchedKey, primaryKey); 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) { handleMatchResult(matchedKey, primaryKey) {

12
dist/setup/index.js vendored
View file

@ -63600,8 +63600,20 @@ class CacheDistributor {
const cachePath = yield this.getCacheGlobalDirectories(); const cachePath = yield this.getCacheGlobalDirectories();
core.saveState(State.CACHE_PATHS, cachePath); core.saveState(State.CACHE_PATHS, cachePath);
core.saveState(State.STATE_CACHE_PRIMARY_KEY, primaryKey); core.saveState(State.STATE_CACHE_PRIMARY_KEY, primaryKey);
try {
const matchedKey = yield cache.restoreCache(cachePath, primaryKey, restoreKey); const matchedKey = yield cache.restoreCache(cachePath, primaryKey, restoreKey);
this.handleMatchResult(matchedKey, primaryKey); 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) { handleMatchResult(matchedKey, primaryKey) {

View file

@ -35,6 +35,7 @@ abstract class CacheDistributor {
core.saveState(State.CACHE_PATHS, cachePath); core.saveState(State.CACHE_PATHS, cachePath);
core.saveState(State.STATE_CACHE_PRIMARY_KEY, primaryKey); core.saveState(State.STATE_CACHE_PRIMARY_KEY, primaryKey);
try {
const matchedKey = await cache.restoreCache( const matchedKey = await cache.restoreCache(
cachePath, cachePath,
primaryKey, primaryKey,
@ -42,6 +43,17 @@ abstract class CacheDistributor {
); );
this.handleMatchResult(matchedKey, primaryKey); 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);
}
}
} }
public handleMatchResult(matchedKey: string | undefined, primaryKey: string) { public handleMatchResult(matchedKey: string | undefined, primaryKey: string) {