-
Notifications
You must be signed in to change notification settings - Fork 772
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inconsistency between readJson and readJsonSync when file does not exist #542
Comments
@jprichardson This inconsistency is actually documented: https://github.com/jprichardson/node-jsonfile#readfilefilename-options-callback Do you know why you built it this way? |
@RyanZim I don't remember... I do remember the option was only in the sync version first. There's a lot of history though in the jsonFile repo on this IIRC - https://github.com/jprichardson/node-jsonfile/search?q=throws&type=Issues&utf8=%E2%9C%93 Generally, I think APIs should be consistent and only break this for good reason - at this moment, I'm not seeing a good reason for the inconsistency. |
So it seems |
@RyanZim I think it is pretty reasonable if we specify |
The
throws
option has an inconsistent behavior betweenreadJson
andreadJsonSync
when the file do not exist:fs.readJsonSync('path', { throws: false});
do not throw if the file do not exist;fs.readJson('path', { throws: false});
do throw if the file do not exist.I would expect a consistent behavior between the two.
Test code:
Outputs:
Versions:
fs-extra
version: 5.0.0The text was updated successfully, but these errors were encountered: