-
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
fse.remove() && fse.removeSync() don't throw error on ENOENT file #246
Comments
This is expected. Since you're trying to remove the file, why would you care if it doesn't already exist? |
Thank you for quick response. I would be just nice to throw an exception for debugging purposes e.g. if incorrect path was passed. |
I would also suggest to add an There are situations where it is useful to get this information, e.g. when implementing a DAV based protocol or a RESTful interface, it is required to return an error if the client tries to delete a resource or collection that does not exits. As of that it is currently required to do a test if the file or directory exits before the But the main point why I would suggest to add the |
Good point! This would be a huge breaking change. If this functionality is really needed (I'm not convinced it is), it should be a separate method. Feel free to open a feature request for that if you are so inclined. |
Many years late to the discussion, could we add a loud ENOENT version under a flag ie |
@CxRes What's the use-case? Seems like it's pretty much of a edge case, since you're the first person since 2016 to need this. |
@RyanZim I for example also still prefer to catch the case where a directory that I want to delete does not exist, because in actually all of the cases when this error would occur in my workflow it would indicate that something went wrong (inconsistencies with the database, race conditions, failed correct transaction handling, ...) and consistent behavior with |
@RaynZim I have a use case where the knowledge of whether something did not exist or was deleted would affect the state of the database tracking it. In case the resource does not exist, I can, for example, skip touching the database or log it differently. There are two things to note: |
OK, PR welcome for further discussion. |
Added a `shoutMissing` flag to remove() options that when set to `true` will emit an error when the specified file or directory is missing. The default is `false`, existing users are not affected. Fixes jprichardson#246 Partially
@RyanZim Please look at the PR above when you can! |
Discussion moved to #840. |
try {
fse.removeSync('/directory/that/does/not/exist/index.js');
} catch (error) {
//no exception will be thrown
}
Similarly,
fse.remove('/directory/that/does/not/exist/index.js', function(error) {
//error is null
console.error(error);
});
fse version 0.26.5
Is it expected behavior? Otherwise, I can help fixing it.
The text was updated successfully, but these errors were encountered: