Skip to content

Commit

Permalink
docs: add error handling to writeFile
Browse files Browse the repository at this point in the history
  • Loading branch information
addetz committed Nov 12, 2024
1 parent 53e59b7 commit 887ce07
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions plugins/packs-integrations.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -527,15 +533,19 @@ async function pluginPacksAndIntegrationsData(context, options) {
apiPackResponse.packMDMap = packMDMap;
apiPackResponse.logoUrlMap = logoUrlMap;
open(`${dirname}${packs_filename}`, "w+", (err, fd) => {
if (err) {
logger.error("An error occurred while opening the JSON file:", err);
return;
}
try {
writeFile(`${dirname}${packs_filename}`, JSON.stringify(apiPackResponse), (err) => {
if (err) {
logger.error("An error occurred while writing the JSON file:", err);
writeFile(`${dirname}${packs_filename}`, JSON.stringify(apiPackResponse), (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);
});
}
});
Expand Down

0 comments on commit 887ce07

Please sign in to comment.