fs.move doesn't return error on moving same nonexistent folder/file
See original GitHub issueIssue:
When i fs.move()
using two paths that are the same and both are invalid(nonexistent) paths, the function does not return an error, which it should since you are trying to move a nonexistent path.
Setup:
This is being ran inside of an electron render, which means its being ran inside of a chrome wrapper. This issue persists through fs-extra 3.0
Example:
fs.move("nonexistent/path","nonexistent/path", (err) => { console.log(err)})
// err returns null
Usage:
I use this in my personal repo: https://github.com/zosman1/The_Archiver/blob/c65ed9dfb7ae0855b1fcb8026204c8d6876a96af/app/index.js#L25
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
How do I move files in node.js? - Stack Overflow
According to seppo0010 comment, I used the rename function to do that. http://nodejs.org/docs/latest/api/fs.html#fs_fs_rename_oldpath_newpath_callback.
Read more >Is there a way to make "mv" fail silently? - Unix Stack Exchange
You want to mute it only in case your glob expression doesn't return results. ... { move $file, $target or warn "Error moving...
Read more >Moving files accidentally to an not existing directory erases files?
As Rinzwind says, moving files to a nonexistent destination directory shouldn't cause data loss when you attempt it using a single mv command....
Read more >File.Move Method (System.IO) | Microsoft Learn
This method works across disk volumes, and it does not throw an exception if the source and destination are the same. Note that...
Read more >node-fs-extra/move.md at master - GitHub
Using overwrite option const fs = require('fs-extra') fs. move('/tmp/somedir', '/tmp/may/already/exist/somedir', { overwrite: true }, err => { if (err) return ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@zosman1 Confirmed this issue.
The reason this behaves this way is that fs-extra is designed to silently do nothing when the source and destination paths are the same. In that case, it doesn’t even touch the filesystem, so no error is raised.
Right now, I’m questioning the wisdom of silently doing nothing when the source & dest is the same. I wonder if we should error out here? @jprichardson @manidlou thoughts?
Done: ~#378~ https://github.com/jprichardson/node-fs-extra/pull/415