Skip to content

Commit e373fb0

Browse files
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.
1 parent a6eaa04 commit e373fb0

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

workers/main/src/common/fileUtils.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,14 @@ export async function writeJsonFile<T = object>(
3030
throw new FileUtilsError(`Failed to write JSON file at "${filePath}"`);
3131
}
3232
}
33+
34+
export async function deleteJsonFile(filePath: string): Promise<void> {
35+
try {
36+
await fs.unlink(filePath);
37+
} catch (error) {
38+
// Ignore ENOENT (file not found) errors as they're expected when clearing
39+
if ((error as NodeJS.ErrnoException).code !== 'ENOENT') {
40+
throw new FileUtilsError(`Failed to delete JSON file at "${filePath}"`);
41+
}
42+
}
43+
}

0 commit comments

Comments
 (0)