Skip to content
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.realpath vs fs.realpath.native differences not documented #45067

Closed
didiercolens opened this issue Oct 19, 2022 · 3 comments · Fixed by #48170
Closed

fs.realpath vs fs.realpath.native differences not documented #45067

didiercolens opened this issue Oct 19, 2022 · 3 comments · Fixed by #48170
Labels
doc Issues and PRs related to the documentations. fs Issues and PRs related to the fs subsystem / file system.

Comments

@didiercolens
Copy link

didiercolens commented Oct 19, 2022

Affected URL(s)

https://nodejs.org/api/fs.html#fsrealpathpath-options-callback

Description of the problem

There is a difference in the errors thrown by fs.realpath and fs.realpath.native, when the path does not exist, fs.realpath throws an error with the path property set to the realpath stopping at the first subpath that does not exist, while the fs.realpath.native throws an error with the path property set to the value of the path argument.

Example:

> fs.realpath('does/not/exist', console.log)
undefined
> [Error: ENOENT: no such file or directory, lstat '/private/tmp/does'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'lstat',
  path: '/private/tmp/does' <==== real path until it does not exist
}
> fs.realpath.native('does/not/exist', console.log)
undefined
> [Error: ENOENT: no such file or directory, realpath 'does/not/exist'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'realpath',
  path: 'does/not/exist' <==== always same value as path argument
}

If this is intentional it should be documented.

This is particularly annoying because fsPromises.realpath runs fs.realpath.native and therefore a coder that would switch from fs.realpath to fsPromises.realpath would expect consistent behaviour and even if the documentation states the fsPrommises uses .native, it does not show the different behaviour highlighted above.

@didiercolens didiercolens added the doc Issues and PRs related to the documentations. label Oct 19, 2022
@VoltrexKeyva VoltrexKeyva added the fs Issues and PRs related to the fs subsystem / file system. label Oct 19, 2022
@juanarbol
Copy link
Member

Hey, this is really good. Do you think you can send a PR documenting this? BTW, thanks again for the report

@didiercolens
Copy link
Author

@juanarbol thank you, I need some guidance because errors are documented in https://github.com/nodejs/node/blob/main/doc/api/errors.md#class-systemerror and this behaviour is specific to 2 fs methods. Should I add a comment in fs.realpath describing the error.path property in case of ENOENT error?

@juanarbol
Copy link
Member

I would extend the scope and put some references to the necessary errors.

aduh95 pushed a commit that referenced this issue May 11, 2024
PR-URL: #48170
Fixes: #45067
Reviewed-By: James M Snell <[email protected]>
targos pushed a commit that referenced this issue May 11, 2024
PR-URL: #48170
Fixes: #45067
Reviewed-By: James M Snell <[email protected]>
marco-ippolito pushed a commit that referenced this issue Jun 17, 2024
PR-URL: #48170
Fixes: #45067
Reviewed-By: James M Snell <[email protected]>
marco-ippolito pushed a commit that referenced this issue Jun 17, 2024
PR-URL: #48170
Fixes: #45067
Reviewed-By: James M Snell <[email protected]>
marco-ippolito pushed a commit that referenced this issue Jun 17, 2024
PR-URL: #48170
Fixes: #45067
Reviewed-By: James M Snell <[email protected]>
EliphazBouye pushed a commit to EliphazBouye/node that referenced this issue Jun 20, 2024
bmeck pushed a commit to bmeck/node that referenced this issue Jun 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc Issues and PRs related to the documentations. fs Issues and PRs related to the fs subsystem / file system.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants