Skip to content
This repository has been archived by the owner on Jul 9, 2024. It is now read-only.

Commit

Permalink
fix(utils): cache error is being rethrown (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
ronnetzer authored Dec 19, 2022
1 parent 04b2397 commit 107c7d5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 15 deletions.
9 changes: 2 additions & 7 deletions packages/utils/src/lib/cache.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,9 @@ describe('cache', () => {
expect(saveCache).toHaveBeenCalledWith(getNxCachePaths(task), 'nx-cache-test-0');
});

it('should fail silently for ReserveCacheError', async () => {
(saveCache as jest.Mock).mockRejectedValueOnce(new ReserveCacheError('test'));
await expect(saveNxCache(context, task)).resolves.toBeUndefined();
});

it('should fail for not ReserveCacheError', async () => {
it('should fail silently', async () => {
(saveCache as jest.Mock).mockRejectedValueOnce(new Error('test'));
await expect(saveNxCache(context, task)).rejects.toThrowError('test');
await expect(saveNxCache(context, task)).resolves.toBeUndefined();
});

it('should not save cache if in debug mode', async () => {
Expand Down
10 changes: 2 additions & 8 deletions packages/utils/src/lib/cache.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { sep } from 'path';

import { ReserveCacheError, restoreCache, saveCache } from '@actions/cache';
import { restoreCache, saveCache } from '@actions/cache';

import { debug, info, logger, success, warning } from './logger';

Expand Down Expand Up @@ -90,13 +90,7 @@ export async function saveNxCache(context: typeof Context, task: Task): Promise<

success(`Successfully saved cache to ${primaryKey}`);
} catch (err) {
// don't throw an error if cache already exists, which may happen due to concurrency
if (err instanceof ReserveCacheError) {
warning(err);
return;
}
// otherwise re-throw
throw err;
warning(err as string);
}
}

Expand Down

0 comments on commit 107c7d5

Please sign in to comment.