jprichardson / node-jsonfile

Easily read/write JSON files.
MIT License
1.2k stars 321 forks source link

Added try,catch to readFileSync #11

Closed ilblog closed 10 years ago

ilblog commented 10 years ago

While readFile is safe, JSON parser in readFileSync can throw exception. Try, catch should solve this issue.

jprichardson commented 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.

jprichardson commented 10 years ago

Ok, changed my mind on this. In 2.0.0 you can pass {throws: false} to readFileSync and it won't throw anymore.

ilblog commented 10 years ago

Thumbs up