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

Fix for compare method not rejecting promise on error #469

Merged
merged 2 commits into from
Dec 31, 2016
Merged

Fix for compare method not rejecting promise on error #469

merged 2 commits into from
Dec 31, 2016

Conversation

recrsn
Copy link
Collaborator

@recrsn recrsn commented Dec 25, 2016

This pull request aims to fix #468 - Compare method not rejecting promise on error

@mention-bot
Copy link

@Agathver, thanks for your PR! By analyzing the history of the files in this pull request, we identified @ncb000gt, @shovon and @ksmyth to be potential reviewers.

@defunctzombie
Copy link
Collaborator

Needs tests (didn't notice if those were added due to the diff noise)

@recrsn
Copy link
Collaborator Author

recrsn commented Dec 26, 2016

I removed the unnecessary changes.

return process.nextTick(function() {
cb(new Error('data and hash arguments required'));
data(new Error('data and hash arguments required'));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't really match the if condition. The user might provide a function for the data argument and then see this error when in fact they did provide an argument.

This also doesn't handle the case where the user passes null for the arguments and does not specify a callback. They will not get a rejection.

The real mistake of the API is to not throw then it is called with the wrong arguments which is what should have happened but given that is not the case. Fixing this to match previous behavior means identifying the error condition and then rejecting with promise or callback as needed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to make it identical to hash, where it is assumed that if the user passes a function in place of parameters, the data and salt arguments are missing and the passed function is the callback which should be called with the error.

May be the error message could be rewritten as 'data and hash must be strings' ?

If the user passes null for either the data or hash, and does not specify a callback, the Promise is rejected.

The previous (v0.8.7) behavior was to fail with TypeError: cb is not a function, But hash used to call the passed method and silently fail if no callback was specified.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no check now in this function for (data == null || hash == null) when no callback is provided (also in the hash function). Is this not going to be an issue?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When no callback is provided this function returns a promise (which is made simply from providing a callback and calling again) and then the null checks are present and the promise is rejected.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I missed that it's simply calling itself again. Thanks!

return process.nextTick(function() {
cb(new Error('data and hash arguments required'));
data(new Error('data and hash arguments required'));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood.

@defunctzombie defunctzombie merged commit 8becdf3 into kelektiv:master Dec 31, 2016
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.

Compare method not rejecting promise on error
4 participants