From b0deb4485a1dea1488efd7a5fe8d0080e93f4a1e Mon Sep 17 00:00:00 2001 From: alvarosabu Date: Tue, 5 Nov 2024 09:27:08 +0100 Subject: [PATCH] feat: more granular error handling on save json file --- src/commands/pull-languages/actions.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/commands/pull-languages/actions.ts b/src/commands/pull-languages/actions.ts index 7f4ebd1..b1d963f 100644 --- a/src/commands/pull-languages/actions.ts +++ b/src/commands/pull-languages/actions.ts @@ -43,12 +43,21 @@ export const saveLanguagesToFile = async (space: string, internationalizationOpt await access(resolvedPath, constants.F_OK) } catch { - await mkdir(resolvedPath, { recursive: true }) + try { + await mkdir(resolvedPath, { recursive: true }) + } + catch (mkdirError) { + handleFileSystemError('mkdir', mkdirError as Error) + return // Exit early if the directory creation fails + } } - return await writeFile(filePath, data, { - mode: 0o600, - }) + try { + await writeFile(filePath, data, { mode: 0o600 }) + } + catch (writeError) { + handleFileSystemError('write', writeError as Error) + } } catch (error) { handleFileSystemError('write', error as Error)