Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

fs.rename returns deceptive error when target path is problematic #7657

Closed
mgenev opened this issue May 20, 2014 · 7 comments
Closed

fs.rename returns deceptive error when target path is problematic #7657

mgenev opened this issue May 20, 2014 · 7 comments
Labels

Comments

@mgenev
Copy link

mgenev commented May 20, 2014

when i try to rename a file and its source path is accurate, but target directory doesn't exist, I get simply ENOENT, rename and it quotes the source path. This made me think for a long time that my source path was problematic when the problem all along was that the target dir doesn't exist and there is no indication in the error of that.

@indutny
Copy link
Member

indutny commented May 20, 2014

What node.js version are you referring to?

@mgenev
Copy link
Author

mgenev commented May 20, 2014

0.10.26

@tjfontaine tjfontaine added the fs label May 21, 2014
@tjfontaine
Copy link

Can you please provide a reproducible test case?

@cjihrig
Copy link

cjihrig commented May 23, 2014

I think this should reproduce the described problem. The error only lists the source file being renamed, even though the target is the problem.

var fs = require('fs');
var assert = require('assert');
var src = 'foo.txt';

fs.writeFileSync(src, 'test');
assert(fs.existsSync(src));
assert(!fs.existsSync('bar'));

fs.rename(src, 'bar/baz.txt', function(error) {
  fs.unlinkSync(src);
  assert(error);
  assert(error.path !== src);
});

@mgenev
Copy link
Author

mgenev commented May 27, 2014

That's exactly correct. It's very easy to reproduce.

@ibash
Copy link

ibash commented May 31, 2014

This is a dupe of #685 , right?

@mmalecki
Copy link

mmalecki commented Aug 7, 2014

@tjfontaine this should be closed as dupe of ^

@indutny indutny closed this as completed Aug 7, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

6 participants