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);
const matchedKey = yield cache.restoreCache(cachePath, primaryKey, restoreKey); try {
this.handleMatchResult(matchedKey, primaryKey); 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) { handleMatchResult(matchedKey, primaryKey) {

16
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);
const matchedKey = yield cache.restoreCache(cachePath, primaryKey, restoreKey); try {
this.handleMatchResult(matchedKey, primaryKey); 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) { handleMatchResult(matchedKey, primaryKey) {

View file

@ -35,13 +35,25 @@ 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);
const matchedKey = await cache.restoreCache( try {
cachePath, const matchedKey = await cache.restoreCache(
primaryKey, cachePath,
restoreKey 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) { public handleMatchResult(matchedKey: string | undefined, primaryKey: string) {