From 49dde45ec4b7d80a3e10a8e0a2522faa213176eb Mon Sep 17 00:00:00 2001 From: addetz <43963729+addetz@users.noreply.github.com> Date: Mon, 11 Nov 2024 21:17:12 +0000 Subject: [PATCH] docs: add error handling to writeFile --- plugins/packs-integrations.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/plugins/packs-integrations.js b/plugins/packs-integrations.js index b7796252c6e..b2a3b5dcedf 100644 --- a/plugins/packs-integrations.js +++ b/plugins/packs-integrations.js @@ -340,19 +340,25 @@ async function mapRepositories(repositories) { } return acc; }, []); + open(`${dirname}${repos_filename}`, "w+", (err, fd) => { + if (err) { + logger.error("An error occurred while opening the JSON file:", err); + return; + } try { - writeFile(`${dirname}${repos_filename}`, JSON.stringify(repoMap), (err) => { - if (err) { - logger.error("An error occurred while writing the JSON file:", err); + writeFile(`${dirname}${repos_filename}`, JSON.stringify(repoMap), (err1) => { + if (err1) { + logger.error("An error occurred while writing the JSON file:", err1); } }); } finally { - close(fd, (err1) => { - if (err1) logger.error("An error occurred while closing the file:", err1); + close(fd, (err2) => { + if (err2) logger.error("An error occurred while closing the file:", err2); }); } }); + return repoMap; }