Rule Definition
To better handle errors coming from synchronous method call, you must ensure to handle these FileSystem methods using try/catch blocks.
Remediation
Add a try/catch block.
Violation Code Sample
// remediation
const fs = require('fs');
fs.unlinkSync('/tmp/hello'); // not sure if we are successfull or not
Fixed Code Sample
// remediation
const fs = require('fs');
try {
fs.unlinkSync('/tmp/hello');
console.log('successfully deleted /tmp/hello');
} catch (err) {
// handle the error
}
Reference
https://nodejs.org/api/fs.html#fs_file_system
Related Technologies
Technical Criterion
Programming Practices - Error and Exception Handling
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.