From e373fb0ee679f6200e044a5cf6a69fb8da78c288 Mon Sep 17 00:00:00 2001 From: "anatoly.shipitz" Date: Wed, 6 Aug 2025 14:44:01 +0200 Subject: [PATCH] Add deleteJsonFile utility function in fileUtils.ts - Introduced a new function `deleteJsonFile` to handle the deletion of JSON files. This function gracefully manages errors by ignoring 'file not found' errors (ENOENT) while throwing a custom error for other issues. - This enhancement improves file management capabilities within the application, allowing for better handling of temporary or unnecessary JSON files. These changes contribute to a more robust utility for file operations. --- workers/main/src/common/fileUtils.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/workers/main/src/common/fileUtils.ts b/workers/main/src/common/fileUtils.ts index a6116c2..c0c26e8 100644 --- a/workers/main/src/common/fileUtils.ts +++ b/workers/main/src/common/fileUtils.ts @@ -30,3 +30,14 @@ export async function writeJsonFile( throw new FileUtilsError(`Failed to write JSON file at "${filePath}"`); } } + +export async function deleteJsonFile(filePath: string): Promise { + try { + await fs.unlink(filePath); + } catch (error) { + // Ignore ENOENT (file not found) errors as they're expected when clearing + if ((error as NodeJS.ErrnoException).code !== 'ENOENT') { + throw new FileUtilsError(`Failed to delete JSON file at "${filePath}"`); + } + } +}