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

emptyDir() callback arguments are inconsistent #287

Closed
rahatarmanahmed opened this issue Oct 14, 2016 · 12 comments
Closed

emptyDir() callback arguments are inconsistent #287

rahatarmanahmed opened this issue Oct 14, 2016 · 12 comments

Comments

@rahatarmanahmed
Copy link

When using emptyDir(), the arguments passed to the callback are inconsistent. When the directory doesn't exist, the arguments are [null, '/path/to/dir']. If the directory does exist, there are no arguments passed.

Reproduce with:

node -e "require('fs-extra').emptyDir('/path/to/nonexistent/directory', function() { console.log(arguments) })"
node -e "require('fs-extra').emptyDir('/path/to/nonexistent/directory', function() { console.log(arguments) })"

which outputs:

{ '0': null,
  '1': '/path/to/nonexistent/directory' }
{}
@jprichardson jprichardson added this to the 1.0.0 milestone Oct 14, 2016
@rahatarmanahmed
Copy link
Author

This seems to happen to ensureDir() as well. I think it happens for any function that has a logic of "mkdir" or "something else", because "mkdir" will return the dirname as an argument, but the "something else" doesn't return an argument.

@RyanZim
Copy link
Collaborator

RyanZim commented Oct 25, 2016

Just a clarification:

emptyDir():

{ '0': null, '1': '/home/ryan/t/fs-ext/noop' }
{}

ensureDir():

{ '0': null, '1': '/home/ryan/t/fs-ext/noop' }
{ '0': null, '1': null }

@RyanZim
Copy link
Collaborator

RyanZim commented Oct 25, 2016

@jprichardson What is the correct arguments signature?

@jprichardson
Copy link
Owner

When in doubt, we should:

  1. Follow the lead of Node.js.
  2. Strive for consistency.

These aren't hard rules though, especially if it means dirtying up the code to ensure that err is either undefined always or null (assuming no Error).

@rahatarmanahmed can you elaborate more on the problem this is causing your code?

@rahatarmanahmed
Copy link
Author

rahatarmanahmed commented Oct 25, 2016

@jprichardson it causes issues when used with a package like run-waterfall. I ran into it while working on this PR: electron/packager@72ab0e7

@RyanZim
Copy link
Collaborator

RyanZim commented Oct 26, 2016

If @rahatarmanahmed wants to submit a PR, SGTM. Suffice to say this isn't high-priority for me.

@rahatarmanahmed
Copy link
Author

rahatarmanahmed commented Oct 26, 2016

Sorry, I only ran into this working on a PR for another project. I don't personally use fs-extra or run-waterfall, so it's not a high-priority for me either 😢 . (Plus it's not entirely a blocker, since there is a workaround).

@RyanZim
Copy link
Collaborator

RyanZim commented Oct 26, 2016

I don't think this is going to get fixed for v1.0.0, so removing the milestone.

@jprichardson If you want to close this as wontfix, IDK.

@RyanZim RyanZim removed this from the 1.0.0 milestone Oct 26, 2016
@jprichardson
Copy link
Owner

@rahatarmanahmed interested in submitting a PR?

@rahatarmanahmed
Copy link
Author

@jprichardson Not really, sorry. Hate to be one of those hit-and-run issue creators, but I don't really have an investment in this project.

@jprichardson
Copy link
Owner

@rahatarmanahmed I appreciate your candid response :)

@RyanZim
Copy link
Collaborator

RyanZim commented Dec 31, 2016

Going to close this as a wont-fix; not saying this will never change, but I don't see myself devoting time to this edge case in the near future. If someone stumbles across this again, PR welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants