From 639c79e4a46964a08887f9e81ef14b06b9a0d977 Mon Sep 17 00:00:00 2001 From: Shubham Tiwari <64764738+tiwarishub@users.noreply.github.com> Date: Mon, 20 Jun 2022 04:47:59 +0000 Subject: [PATCH] added info error as well --- packages/cache/__tests__/saveCache.test.ts | 14 +++++++------- packages/cache/src/cache.ts | 7 ++++++- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/packages/cache/__tests__/saveCache.test.ts b/packages/cache/__tests__/saveCache.test.ts index ed370720..aa03f597 100644 --- a/packages/cache/__tests__/saveCache.test.ts +++ b/packages/cache/__tests__/saveCache.test.ts @@ -62,7 +62,7 @@ test('save with large cache outputs should fail', async () => { const cacheId = await saveCache([filePath], primaryKey) expect(cacheId).toBe(-1) expect(logWarningMock).toHaveBeenCalledTimes(1) - expect(logWarningMock).toHaveBeenCalledWith('Fail to save: Error: Cache size of ~11264 MB (11811160064 B) is over the 10GB limit, not saving cache.') + expect(logWarningMock).toHaveBeenCalledWith('Fail to save: Cache size of ~11264 MB (11811160064 B) is over the 10GB limit, not saving cache.') const archiveFolder = '/foo/bar' @@ -112,7 +112,7 @@ test('save with large cache outputs should fail in GHES with error message', asy const cacheId = await saveCache([filePath], primaryKey) expect(cacheId).toBe(-1) expect(logWarningMock).toHaveBeenCalledTimes(1) - expect(logWarningMock).toHaveBeenCalledWith('Fail to save: Error: The cache filesize must be between 0 and 1073741824 bytes') + expect(logWarningMock).toHaveBeenCalledWith('Fail to save: The cache filesize must be between 0 and 1073741824 bytes') const archiveFolder = '/foo/bar' expect(reserveCacheMock).toHaveBeenCalledTimes(1) @@ -158,7 +158,7 @@ test('save with large cache outputs should fail in GHES without error message', const cacheId = await saveCache([filePath], primaryKey) expect(cacheId).toBe(-1) expect(logWarningMock).toHaveBeenCalledTimes(1) - expect(logWarningMock).toHaveBeenCalledWith('Fail to save: Error: Cache size of ~11264 MB (11811160064 B) is over the data cap limit, not saving cache.') + expect(logWarningMock).toHaveBeenCalledWith('Fail to save: Cache size of ~11264 MB (11811160064 B) is over the data cap limit, not saving cache.') const archiveFolder = '/foo/bar' expect(reserveCacheMock).toHaveBeenCalledTimes(1) @@ -174,7 +174,7 @@ test('save with large cache outputs should fail in GHES without error message', test('save with reserve cache failure should fail', async () => { const paths = ['node_modules'] const primaryKey = 'Linux-node-bb828da54c148048dd17899ba9fda624811cfb43' - const logWarningMock = jest.spyOn(core, "warning"); + const logInfoMock = jest.spyOn(core, "info"); const reserveCacheMock = jest .spyOn(cacheHttpClient, 'reserveCache') @@ -196,8 +196,8 @@ test('save with reserve cache failure should fail', async () => { const cacheId = await saveCache(paths, primaryKey) expect(cacheId).toBe(-1) - expect(logWarningMock).toHaveBeenCalledTimes(1) - expect(logWarningMock).toHaveBeenCalledWith('Fail to save: ReserveCacheError: Unable to reserve cache with key ${primaryKey}, another job may be creating this cache.') + expect(logInfoMock).toHaveBeenCalledTimes(1) + expect(logInfoMock).toHaveBeenCalledWith(`Fail to save: Unable to reserve cache with key ${primaryKey}, another job may be creating this cache. More details: undefined`) expect(reserveCacheMock).toHaveBeenCalledTimes(1) expect(reserveCacheMock).toHaveBeenCalledWith(primaryKey, paths, { @@ -239,7 +239,7 @@ test('save with server error should fail', async () => { await saveCache([filePath], primaryKey) expect(logWarningMock).toHaveBeenCalledTimes(1) - expect(logWarningMock).toHaveBeenCalledWith('Fail to save: Error: HTTP Error Occurred') + expect(logWarningMock).toHaveBeenCalledWith('Fail to save: HTTP Error Occurred') expect(reserveCacheMock).toHaveBeenCalledTimes(1) expect(reserveCacheMock).toHaveBeenCalledWith(primaryKey, [filePath], { diff --git a/packages/cache/src/cache.ts b/packages/cache/src/cache.ts index b446bbc4..be448538 100644 --- a/packages/cache/src/cache.ts +++ b/packages/cache/src/cache.ts @@ -225,7 +225,12 @@ export async function saveCache( core.debug(`Saving Cache (ID: ${cacheId})`) await cacheHttpClient.saveCache(cacheId, archivePath, options) } catch(error) { - core.warning(`Fail to save: ${error}`) + const typedError = error as Error; + if (typedError.name === ReserveCacheError.name) { + core.info(`Fail to save: ${typedError.message}`) + } else { + core.warning(`Fail to save: ${typedError.message}`) + } } finally { // Try to delete the archive to save space try {