From bd08e7b7cd26bc4c1ecc50390b3e3da202dd6e32 Mon Sep 17 00:00:00 2001 From: Daz DeBoer Date: Tue, 14 Sep 2021 13:38:48 -0600 Subject: [PATCH] Do not fail build on error restoring artifact for marker Instead, catch and report these errors before continuing. --- src/cache-gradle-user-home.ts | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/cache-gradle-user-home.ts b/src/cache-gradle-user-home.ts index 49cf82e..1d1892b 100644 --- a/src/cache-gradle-user-home.ts +++ b/src/cache-gradle-user-home.ts @@ -72,16 +72,22 @@ export class GradleUserHomeCache extends AbstractCache { const key = path.relative(this.getGradleUserHome(), artifactFile) const cacheKey = `gradle-artifact-${key}` - const restoreKey = await cache.restoreCache( - [artifactFile], - cacheKey - ) - if (restoreKey) { - this.debug(`Restored ${cacheKey} from cache to ${artifactFile}`) - } else { - core.warning( - `Failed to restore from ${cacheKey} to ${artifactFile}` + try { + const restoreKey = await cache.restoreCache( + [artifactFile], + cacheKey ) + if (restoreKey) { + this.debug( + `Restored ${cacheKey} from cache to ${artifactFile}` + ) + } else { + core.warning( + `Failed to restore from ${cacheKey} to ${artifactFile}` + ) + } + } catch (error) { + core.warning(`Error restoring ${cacheKey}: ${error}`) } } else { this.debug( @@ -162,16 +168,15 @@ export class GradleUserHomeCache extends AbstractCache { await cache.saveCache([artifactFile], cacheKey) } catch (error) { // Fail on validation errors or non-errors (the latter to keep Typescript happy) - if ( - error instanceof cache.ValidationError || - !(error instanceof Error) - ) { + if (error instanceof cache.ValidationError) { throw error } else if (error instanceof cache.ReserveCacheError) { // These are expected if the artifact is already cached this.debug(error.message) - } else { + } else if (error instanceof Error) { core.warning(error.message) + } else { + core.warning(`${error}`) } }