Skip to content

Commit 03eb867

Browse files
Add error handling for saving and restoring cache (actions#618)
1 parent b41aaf9 commit 03eb867

File tree

8 files changed

+695
-1057
lines changed

8 files changed

+695
-1057
lines changed

.licenses/npm/@actions/cache.dep.yml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.licenses/npm/@azure/abort-controller.dep.yml

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

__tests__/cache-save.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ describe('run', () => {
225225
expect(setFailedSpy).not.toHaveBeenCalled();
226226
});
227227

228-
it('saves with error from toolkit, should fail workflow', async () => {
228+
it('saves with error from toolkit, should not fail the workflow', async () => {
229229
inputs['cache'] = 'npm';
230230
getStateSpy.mockImplementation((name: string) => {
231231
if (name === State.STATE_CACHE_PRIMARY_KEY) {
@@ -247,7 +247,7 @@ describe('run', () => {
247247
expect(getStateSpy).toHaveBeenCalledTimes(3);
248248
expect(infoSpy).not.toHaveBeenCalledWith();
249249
expect(saveCacheSpy).toHaveBeenCalled();
250-
expect(setFailedSpy).toHaveBeenCalled();
250+
expect(setFailedSpy).not.toHaveBeenCalled();
251251
});
252252
});
253253

dist/cache-save/index.js

+329-514
Large diffs are not rendered by default.

dist/setup/index.js

+321-514
Large diffs are not rendered by default.

package-lock.json

+19-17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cache-distributions/cache-distributor.ts

+11-6
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,18 @@ abstract class CacheDistributor {
3939
const cachePath = await this.getCacheGlobalDirectories();
4040

4141
core.saveState(State.CACHE_PATHS, cachePath);
42-
core.saveState(State.STATE_CACHE_PRIMARY_KEY, primaryKey);
4342

44-
const matchedKey = await cache.restoreCache(
45-
cachePath,
46-
primaryKey,
47-
restoreKey
48-
);
43+
let matchedKey: string | undefined;
44+
try {
45+
matchedKey = await cache.restoreCache(cachePath, primaryKey, restoreKey);
46+
} catch (err) {
47+
const message = (err as Error).message;
48+
core.info(`[warning]${message}`);
49+
core.setOutput('cache-hit', false);
50+
return;
51+
}
52+
53+
core.saveState(State.STATE_CACHE_PRIMARY_KEY, primaryKey);
4954

5055
await this.handleLoadedCache();
5156

src/cache-save.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,16 @@ async function saveCache(packageManager: string) {
4343
return;
4444
}
4545

46-
const cacheId = await cache.saveCache(cachePaths, primaryKey);
46+
let cacheId = 0;
47+
48+
try {
49+
cacheId = await cache.saveCache(cachePaths, primaryKey);
50+
} catch (err) {
51+
const message = (err as Error).message;
52+
core.info(`[warning]${message}`);
53+
return;
54+
}
55+
4756
if (cacheId == -1) {
4857
return;
4958
}

0 commit comments

Comments
 (0)