Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
fs: implement
fsp.exists
#39968base: main
Are you sure you want to change the base?
fs: implement
fsp.exists
#39968Changes from 3 commits
74a44f7
b13b686
e9df79e
bf9a481
abe5717
51aeba6
cfaf771
10717fb
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't really check if the file exists, which is why the name is misleading, see #39960 (comment).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. It makes sense. Do you have a better name suggestion? Or like
os.path.exists
on Python, is a sepecial note sufficient?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think
access()
has already validated the path.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but
access()
is called in thetry
block.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the problem is, if we got a wrong path, should
exists()
returnfalse
or throw an error.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
node/lib/fs.js
Lines 291 to 295 in 73d5f8a
fs.existsSync()
returnsfalse
if path validation failed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to
node/lib/fs.js
Lines 279 to 284 in 73d5f8a
fsPromises.exists
.Maybe we should even go further and also throw if the error is not ENOENT. For example a permission error now ends up in returning
false
but we actually don't know if the file exists or not.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently,
fs.existsSync(path)
returnsfalse
when path validation failed, even path is not astring
. e.g.I would think it is a bug(?), since docs says it only allows path of type
<string> | <Buffer> | <URL>
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we throws, the behaivor of 3 APIs are very different:
fs.exists()
: wrong callback signature;fs.existsSync()
: eats errors;fsPromise.exists()
: throws errors.And actually they just do the same thing in different async ways. I think we shouldn't make the behaivor more chaotic.
I think there're 2 ways to choose:
fsPromise.exists()
: never throws;fs.existsSync()
's TODO and make it throws.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to make
fs.existsSync
throw, we should probably make the error swallowing go through a complete deprecation first to make sure this won't break the ecosystem.