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

doc: add err param to fs.copyFile callback #53234

Closed
wants to merge 2 commits into from

Conversation

F3n67u
Copy link
Member

@F3n67u F3n67u commented May 31, 2024

Fix #53230

Related issue: #52916

@nodejs-github-bot nodejs-github-bot added fs Issues and PRs related to the fs subsystem / file system. needs-ci PRs that need a full CI run. labels May 31, 2024
@RedYetiDev
Copy link
Member

RedYetiDev commented May 31, 2024

I believe fs.cp also needs this treatment

Copy link
Contributor

@LiviaMedeiros LiviaMedeiros left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM as is; however all related changes that should be made: returned value for fs.cpSync(), fs.copyFileSync(); and values passed to callback for fs.cp(), fs.copyFile().

Note that there is undefined explicitly passed as second parameter to fs.cp()'s callback on success: this happens, because cpFn() returns promise resolving with undefined and callback-based cp() is made using util.callbackify(). If this was unintentional, I guess it might be better to change it before documenting (especially since these API are marked as stable now...)

@F3n67u
Copy link
Member Author

F3n67u commented May 31, 2024

LGTM as is; however all related changes that should be made: returned value for fs.cpSync(), fs.copyFileSync(); and values passed to callback for fs.cp(), fs.copyFile().

Note that there is undefined explicitly passed as second parameter to fs.cp()'s callback on success: this happens, because cpFn() returns promise resolving with undefined and callback-based cp() is made using util.callbackify(). If this was unintentional, I guess it might be better to change it before documenting (especially since these API are marked as stable now...)

I have two questions:

  1. Why we need to make changes to returned value for fs.cpSync() and fs.copyFileSync()? They both have no return value. Do you mean we have to document they return nothing(void)?

  2. I just checked utils.callbackify(), err would be null instead of undefined when success. It seems the undefined value issue is not a problem?

node/lib/util.js

Lines 188 to 190 in 88d0701

ReflectApply(original, this, args)
.then((ret) => process.nextTick(cb, null, ret),
(rej) => process.nextTick(callbackifyOnRejected, rej, cb));

@RedYetiDev RedYetiDev added the doc Issues and PRs related to the documentations. label May 31, 2024
@LiviaMedeiros
Copy link
Contributor

  • Why we need to make changes to returned value for fs.cpSync() and fs.copyFileSync()? They both have no return value. Do you mean we have to document they return nothing(void)?

Yes, they return undefined and we should make this explicit in the docs. Doesn't necessarily have to be done in this PR, my personal preference would be aligning whole file to * Returns: {something} syntax and removing redundant "Returns undefined"s in function descriptions.

  • I just checked utils.callbackify(), err would be null instead of undefined when success. It seems the undefined value issue is not a problem?

err is the first parameter which is indeed null on success. When fs.cp() succeeds, it also passes undefined explicitly as second parameter to the callback. i.e. fs.cp(src, dst, (...params) => { console.log(params.length); }); would print 1 on error and 2 on success.

@F3n67u
Copy link
Member Author

F3n67u commented May 31, 2024

err is the first parameter which is indeed null on success. When fs.cp() succeeds, it also passes undefined explicitly as second parameter to the callback. i.e. fs.cp(src, dst, (...params) => { console.log(params.length); }); would print 1 on error and 2 on success.

Sorry. I misunderstood you. If that's the case, can we consider to fix it in another PR if it's necessary?

FYI, I added err to fs.cp()'s callback as well.

@LiviaMedeiros
Copy link
Contributor

Sorry. I misunderstood you. If that's the case, can we consider to fix it in another PR if it's necessary?

Yes, of course.

@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot
Copy link
Collaborator

@F3n67u F3n67u added the commit-queue Add this label to land a pull request using GitHub Actions. label Jun 3, 2024
@nodejs-github-bot nodejs-github-bot added commit-queue-failed An error occurred while landing this pull request using GitHub Actions. and removed commit-queue Add this label to land a pull request using GitHub Actions. labels Jun 3, 2024
@nodejs-github-bot
Copy link
Collaborator

Commit Queue failed
- Loading data for nodejs/node/pull/53234
✔  Done loading data for nodejs/node/pull/53234
----------------------------------- PR info ------------------------------------
Title      doc: add `err` param to fs.copyFile callback (#53234)
Author     Feng Yu  (@F3n67u)
Branch     F3n67u:docs-copyfile-err -> nodejs:main
Labels     doc, fs, needs-ci
Commits    2
 - doc: add `err` param to fs.copyFile callback
 - doc: add err param to fs.cp callback
Committers 1
 - Feng Yu 
PR-URL: https://github.com/nodejs/node/pull/53234
Reviewed-By: LiviaMedeiros 
Reviewed-By: Luigi Pinca 
------------------------------ Generated metadata ------------------------------
PR-URL: https://github.com/nodejs/node/pull/53234
Reviewed-By: LiviaMedeiros 
Reviewed-By: Luigi Pinca 
--------------------------------------------------------------------------------
   ℹ  This PR was created on Fri, 31 May 2024 19:42:40 GMT
   ✔  Approvals: 2
   ✔  - LiviaMedeiros (@LiviaMedeiros): https://github.com/nodejs/node/pull/53234#pullrequestreview-2091640423
   ✔  - Luigi Pinca (@lpinca): https://github.com/nodejs/node/pull/53234#pullrequestreview-2092020833
   ✔  Last GitHub CI successful
   ℹ  Last Full PR CI on 2024-06-03T11:00:38Z: https://ci.nodejs.org/job/node-test-pull-request/59633/
- Querying data for job/node-test-pull-request/59633/
   ✔  Last Jenkins CI successful
--------------------------------------------------------------------------------
   ✔  No git cherry-pick in progress
   ✔  No git am in progress
   ✔  No git rebase in progress
--------------------------------------------------------------------------------
- Bringing origin/main up to date...
From https://github.com/nodejs/node
 * branch                  main       -> FETCH_HEAD
✔  origin/main is now up-to-date
- Downloading patch for 53234
From https://github.com/nodejs/node
 * branch                  refs/pull/53234/merge -> FETCH_HEAD
✔  Fetched commits as 58711c2f8dbb..da77ab798ffd
--------------------------------------------------------------------------------
[main 296e9c7027] doc: add `err` param to fs.copyFile callback
 Author: Feng Yu 
 Date: Fri May 31 12:14:26 2024 -0700
 2 files changed, 2 insertions(+), 1 deletion(-)
[main a7bf82a713] doc: add err param to fs.cp callback
 Author: Feng Yu 
 Date: Fri May 31 14:45:18 2024 -0700
 2 files changed, 2 insertions(+), 1 deletion(-)
   ✔  Patches applied
There are 2 commits in the PR. Attempting autorebase.
Rebasing (2/4)

Executing: git node land --amend --yes
--------------------------------- New Message ----------------------------------
doc: add err param to fs.copyFile callback

PR-URL: #53234
Reviewed-By: LiviaMedeiros [email protected]
Reviewed-By: Luigi Pinca [email protected]

[detached HEAD 391e1618e8] doc: add err param to fs.copyFile callback
Author: Feng Yu [email protected]
Date: Fri May 31 12:14:26 2024 -0700
2 files changed, 2 insertions(+), 1 deletion(-)
Rebasing (3/4)
Rebasing (4/4)

Executing: git node land --amend --yes
--------------------------------- New Message ----------------------------------
doc: add err param to fs.cp callback

PR-URL: #53234
Reviewed-By: LiviaMedeiros [email protected]
Reviewed-By: Luigi Pinca [email protected]

[detached HEAD f808a8dfaa] doc: add err param to fs.cp callback
Author: Feng Yu [email protected]
Date: Fri May 31 14:45:18 2024 -0700
2 files changed, 2 insertions(+), 1 deletion(-)

Successfully rebased and updated refs/heads/main.

ℹ Add commit-queue-squash label to land the PR as one commit, or commit-queue-rebase to land as separate commits.

https://github.com/nodejs/node/actions/runs/9354148429

@F3n67u F3n67u added commit-queue-rebase Add this label to allow the Commit Queue to land a PR in several commits. commit-queue Add this label to land a pull request using GitHub Actions. and removed commit-queue-failed An error occurred while landing this pull request using GitHub Actions. labels Jun 3, 2024
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Jun 3, 2024
@nodejs-github-bot
Copy link
Collaborator

Landed in 21f38f8...eae75fe

nodejs-github-bot pushed a commit that referenced this pull request Jun 3, 2024
PR-URL: #53234
Reviewed-By: LiviaMedeiros <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
nodejs-github-bot pushed a commit that referenced this pull request Jun 3, 2024
PR-URL: #53234
Reviewed-By: LiviaMedeiros <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
@F3n67u F3n67u deleted the docs-copyfile-err branch June 3, 2024 22:52
RafaelGSS pushed a commit that referenced this pull request Jun 7, 2024
PR-URL: #53234
Reviewed-By: LiviaMedeiros <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
RafaelGSS pushed a commit that referenced this pull request Jun 7, 2024
PR-URL: #53234
Reviewed-By: LiviaMedeiros <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
@RafaelGSS RafaelGSS mentioned this pull request Jun 7, 2024
sophonieb pushed a commit to sophonieb/node that referenced this pull request Jun 20, 2024
PR-URL: nodejs#53234
Reviewed-By: LiviaMedeiros <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
sophonieb pushed a commit to sophonieb/node that referenced this pull request Jun 20, 2024
PR-URL: nodejs#53234
Reviewed-By: LiviaMedeiros <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
bmeck pushed a commit to bmeck/node that referenced this pull request Jun 22, 2024
PR-URL: nodejs#53234
Reviewed-By: LiviaMedeiros <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
bmeck pushed a commit to bmeck/node that referenced this pull request Jun 22, 2024
PR-URL: nodejs#53234
Reviewed-By: LiviaMedeiros <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
marco-ippolito pushed a commit that referenced this pull request Jul 19, 2024
PR-URL: #53234
Reviewed-By: LiviaMedeiros <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
marco-ippolito pushed a commit that referenced this pull request Jul 19, 2024
PR-URL: #53234
Reviewed-By: LiviaMedeiros <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
marco-ippolito pushed a commit that referenced this pull request Jul 19, 2024
PR-URL: #53234
Reviewed-By: LiviaMedeiros <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
marco-ippolito pushed a commit that referenced this pull request Jul 19, 2024
PR-URL: #53234
Reviewed-By: LiviaMedeiros <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
commit-queue-rebase Add this label to allow the Commit Queue to land a PR in several commits. doc Issues and PRs related to the documentations. fs Issues and PRs related to the fs subsystem / file system. needs-ci PRs that need a full CI run.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

In "fs.copyFile(src, dest[, mode], callback)" , for callback,'err' is not defined.
5 participants