Skip to content

Commit

Permalink
fix: handle missing cache folder during clean-up (#365)
Browse files Browse the repository at this point in the history
  • Loading branch information
rmarescu authored Feb 25, 2025
1 parent d1c9ef4 commit 5dd5841
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/shortest/src/cache/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ export const cleanUpCache = async ({
} = {}) => {
const log = getLogger();
log.debug("Cleaning up cache", { forcePurge });

if (!existsSync(dirPath)) {
log.debug("Cache directory does not exist", { dirPath });
return;
}

const files = await fs.readdir(dirPath);
const now = Date.now();

Expand Down
7 changes: 7 additions & 0 deletions packages/shortest/tests/unit/cache/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,12 @@ describe("cache", () => {

await expect(fs.access(nonJsonFile)).resolves.toBeUndefined();
});

it("handles non-existent cache directory", async () => {
const nonExistentDir = path.join(CACHE_DIR_PATH, "non-existent");
await expect(
cleanUpCache({ dirPath: nonExistentDir }),
).resolves.toBeUndefined();
});
});
});

0 comments on commit 5dd5841

Please sign in to comment.