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

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

Closed
Vikranthraosb opened this issue May 31, 2024 · 6 comments
Labels
doc Issues and PRs related to the documentations. fs Issues and PRs related to the fs subsystem / file system.

Comments

@Vikranthraosb
Copy link

Affected URL(s)

https://nodejs.org/docs/latest/api/fs.html#fscopyfilesrc-dest-mode-callback

Description of the problem

There should be an "err" in the callback function for copyFile model, which is absent. Please do add it..

@Vikranthraosb Vikranthraosb added the doc Issues and PRs related to the documentations. label May 31, 2024
@RedYetiDev RedYetiDev added the fs Issues and PRs related to the fs subsystem / file system. label May 31, 2024
@RedYetiDev
Copy link
Member

RedYetiDev commented May 31, 2024

import { copyFile, constants } from 'node:fs';

function callback(err) {
  if (err) throw err;
  console.log('source.txt was copied to destination.txt');
}

// destination.txt will be created or overwritten by default.
copyFile('source.txt', 'destination.txt', callback);

// By using COPYFILE_EXCL, the operation will fail if destination.txt exists.
copyFile('source.txt', 'destination.txt', constants.COPYFILE_EXCL, callback); 

The documentation mentions an err argument in the callback demo code, but no where else in the docs, CC @nodejs/fs

@F3n67u
Copy link
Member

F3n67u commented May 31, 2024

From my test, fs.copyFile's callback has a err param.

$ node test.mjs 
file:///test.mjs:4
  if (err) throw err;
           ^

[Error: ENOENT: no such file or directory, copyfile 'source.txt' -> 'destination.txt'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'copyfile',
  path: 'source.txt',
  dest: 'destination.txt'
}

Node.js v22.2.0


$ cat test.mjs                                                                
import { copyFile } from 'node:fs';

function callback(err) {
  if (err) throw err;
  console.log('source.txt was copied to destination.txt');
}

// destination.txt will be created or overwritten by default.
copyFile('source.txt', 'destination.txt', callback);

@RedYetiDev
Copy link
Member

I ran the same code and got the same result, this seems like a doc-only issue. @Vikranthraosb is that was you were referring to?

@Vikranthraosb
Copy link
Author

Vikranthraosb commented Jun 2, 2024

yes. it's an doc-only issue.

@F3n67u
Copy link
Member

F3n67u commented Jun 6, 2024

yes. it's not an doc-only issue.

If it's not an doc-only issue, could you please clarify what exactly the issue is?

@RedYetiDev
Copy link
Member

Fixed by #53234

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