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

Make callbacks use correct number of arguments #10

Closed
wants to merge 1 commit into from

Conversation

bruse
Copy link

@bruse bruse commented May 16, 2014

In the functions where 'fs' gives a callback of the form function(err),
mock-fs will give a callback of the form function(err, undefined). This
is not equivalent, and will mean using mock-fs functions in place like
some of async.js flow control functions will cause a different behaviour
than the native 'fs' functions.

See https://gist.github.com/bruse/5e5ba24bc5109090f75b for an example
of this inconsistent behavior.

This is one way of fixing it. If we are always sure that the functions that
are supposed to return data never returns undefined, we can make it a
lot shorter I suppose, but I chose to be explicit.

What do you think?

In the functions where 'fs' gives a callback of the form function(err),
mock-fs will give a callback of the form function(err, undefined). This
is not equivalent, and will mean using mock-fs functions in place like
some of async.js flow control functions will cause a different behaviour
than the native 'fs' functions.

See https://gist.github.com/bruse/5e5ba24bc5109090f75b for an example
of this inconsistent behavior.
@tschaub
Copy link
Owner

tschaub commented May 16, 2014

Thanks for the report @bruse. I like that your changes here explicitly force the callback arity, but I think the changes in #11 might be easier to maintain. Let me know if you think that will suffice or if it misses some cases.

@tschaub
Copy link
Owner

tschaub commented May 16, 2014

Another alternative would be to add callback arguments when calling maybeCallback. E.g.

  return maybeCallback(callback, this, function(err, exists) {
  // ...
  };

And then maybeCallback could check func.length. This would be equivalent to your change.

I'm inclined to start with the changes in #11 and then make a more involved change if another issue comes up.

@tschaub tschaub closed this in #11 May 16, 2014
@bruse
Copy link
Author

bruse commented May 18, 2014

Sounds good. I'm not very familiar with your code base, but if you're confident that the functions related to the cases where we actually expect two arguments never return undefined, this indeed looks better.

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

Successfully merging this pull request may close these issues.

2 participants