Skip to content

Commit

Permalink
fix: catch stringify errors
Browse files Browse the repository at this point in the history
  • Loading branch information
maehr committed Dec 19, 2023
1 parent 027e905 commit f2fb80a
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions utils/sortJSON.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,18 @@ fs.readFile(filepath, 'utf-8', (err, data) => {
jsonData.sort((a, b) => a.title.localeCompare(b.title));

// Write the sorted and amended JSON data back to the file
fs.writeFile(filepath, JSON.stringify(jsonData, null, 2), (err) => {
if (err) {
console.error(`Error writing file: ${err.message}`);
return;
}
console.log(`File "${filepath}" sorted and structured successfully.`);
});
try {
const jsonString = JSON.stringify(jsonData, null, 2);
fs.writeFile(filepath, jsonString, (err) => {
if (err) {
console.error(`Error writing file: ${err.message}`);
return;
}
console.log(`File "${filepath}" sorted and structured successfully.`);
});
} catch (error) {
console.error(`Error stringifying JSON data: ${error.message}`);
}
} catch (error) {
console.error(`Error parsing JSON data: ${error.message}`);
}
Expand Down

0 comments on commit f2fb80a

Please sign in to comment.