Skip to content

Handle throws in type parsers #1218

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 2 commits into from
Mar 6, 2017
Merged

Conversation

LinusU
Copy link
Contributor

@LinusU LinusU commented Feb 15, 2017

Fixes #1204

lib/query.js Outdated
row = this._result.parseRow(msg.fields);
} catch (err) {
if(this.callback) {
return this.callback(err);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This will call the callback at least twice if there are errors: once for each errored row, and then once to incorrectly indicate a successful completion, with errored rows missing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, looking into it now 👍

@LinusU
Copy link
Contributor Author

LinusU commented Feb 21, 2017

@charmander should be fixed now :)

@LinusU LinusU force-pushed the throw-in-type-parser branch from f309a21 to 8a01e1d Compare February 21, 2017 11:21
@LinusU LinusU force-pushed the throw-in-type-parser branch from 8a01e1d to a0c341c Compare February 21, 2017 15:09
@LinusU
Copy link
Contributor Author

LinusU commented Feb 21, 2017

@charmander Studied the code more carefully and came up with what I think is a more proper solution. This should now handle the errors correctly and the tests should test it properly (e.g. was missing assert.calls before)

test('handles throws in type parsers', function() {

types.setTypeParser('special oid that will throw', function () {
throw Object.assign(new Error('Test'), { throwInTypeParser: true });
Copy link
Collaborator

Choose a reason for hiding this comment

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

Object.assign isn’t compatible with Node ≤ 0.12.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It might be best to create the error outside the type parser and check that it’s equal to the emitted error rather than adding throwInTypeParser.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Very smart, I'll fix that today 👌

@LinusU
Copy link
Contributor Author

LinusU commented Feb 22, 2017

Error: node-v0.12.18-headers.tar.gz local checksum 05e09ef1bb70bab3bff45f677f8a199c3535c4efce815d9819beb683fd4471d1 not match remote 992f8d2bde6959abd8e5d7e9973b5e87c77af28ee9ca628dbf9c004ef5f7f42b

I don't think this failure is related to my commit :) restarting the build...

@LinusU LinusU force-pushed the throw-in-type-parser branch from 703f12d to fd30e95 Compare February 22, 2017 08:47
@LinusU
Copy link
Contributor Author

LinusU commented Feb 22, 2017

🤔 same error again, seems like something is broken on Travis or the Node.js releases server...

@LinusU LinusU force-pushed the throw-in-type-parser branch from fd30e95 to 2c4b363 Compare February 22, 2017 10:23
@LinusU
Copy link
Contributor Author

LinusU commented Feb 22, 2017

...and the build passes! 🎉 🎉

@LinusU
Copy link
Contributor Author

LinusU commented Feb 27, 2017

ping @brianc, any chance of getting this merged? :)

@LinusU
Copy link
Contributor Author

LinusU commented Mar 6, 2017

ping @brianc, I would really appreciate it if we could merge this one 🙌

@brianc
Copy link
Owner

brianc commented Mar 6, 2017

Nevermind - I see what's going on now - had to read the entire query file.

@brianc brianc merged commit 5cb38f5 into brianc:master Mar 6, 2017
@brianc
Copy link
Owner

brianc commented Mar 6, 2017

Publishing new patch version to npm now - sorry for the delay.

@LinusU
Copy link
Contributor Author

LinusU commented Mar 7, 2017

Thank you ❤️

@LinusU LinusU deleted the throw-in-type-parser branch March 7, 2017 07:42
@LinusU LinusU restored the throw-in-type-parser branch March 9, 2017 14:11
@LinusU LinusU deleted the throw-in-type-parser branch March 9, 2017 14:34
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.

4 participants