Closed ilblog closed 10 years ago
Sorry, this is intentional. It's common practice for synchronous APIs to force error handling on the consumer. Otherwise, someone may just assume that the file is empty. As much as I really like this, it violates the consumer expectations.
Ok, changed my mind on this. In 2.0.0
you can pass {throws: false}
to readFileSync
and it won't throw anymore.
Thumbs up
While readFile is safe, JSON parser in readFileSync can throw exception. Try, catch should solve this issue.