Skip to content

Error Handling for null Params to Client.prototype.query() #1651

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

Merged
merged 1 commit into from
Oct 3, 2018

Conversation

patrickrgaffney
Copy link
Contributor

Add's a basic assertion to Client.prototype.query() ensuring that config is not null or undefined. This fixes #628 — which was closed, but the behavior described in that issue lives on. I added some additional tests around the new logic.

I ran into the same problem described in that issue — some bad destructing logic on my end led to config being undefined when calling query(). That results in a TypeError when the typeof config.submit === 'function' assertion is executed. The behavior is still basically the same, except that the error is detected, described, and sent to the users callback or Promise.rejected.

@sehrope
Copy link
Contributor

sehrope commented May 18, 2018

Looks good to me.

@abenhamdine
Copy link
Contributor

why not simply check config falsyness ?
I don't think a falsy value could be useful here, or maybe I miss something ?

@charmander
Copy link
Collaborator

Type errors tend to throw synchronously. I don’t see a reason to break that pattern for null and undefined specifically – it just needs a more specific error message – so how about:

if (config == null) {
  throw new TypeError('Query was null or undefined')
}

@patrickrgaffney
Copy link
Contributor Author

Just made the changes and rebased such that the TypeError would always throw synchronously — the tests have also been updated.


test('handles errors', function () {
var client = helper.client()
var error = new Error('Client was passed a null or undefined query')
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this variable unused?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, must have missed it when I fixed the tests. I'll push up again.

@brianc
Copy link
Owner

brianc commented Oct 3, 2018

Thanks for this! sorry for the delay. Will push a new version soon.

@brianc brianc merged commit 11a4793 into brianc:master Oct 3, 2018
@patrickrgaffney patrickrgaffney deleted the null-queries branch October 3, 2018 15:36
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.

client.query breaks if null is passed into query
5 participants