Skip to content
This repository was archived by the owner on Dec 30, 2019. It is now read-only.

Don’t create promises when callbacks are provided - #31

Merged
brianc merged 3 commits into
brianc:masterfrom
charmander:promise-xor-callback
Dec 4, 2016
Merged

brianc merged 3 commits into
brianc:masterfrom
charmander:promise-xor-callback

Conversation

@charmander

@charmander charmander commented Oct 28, 2016 •

Copy link
Copy Markdown
Collaborator

One consequence is that a rejected promise will be unhandled, which is currently annoying, but also dangerous in the future:

DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

The way callbacks are used currently also causes #24 (hiding of errors thrown synchronously from the callback). One fix for that would be to call them asynchronously from inside the new Promise() executor:

process.nextTick(cb, error);

I don’t think it’s worth implementing, though, since it would still be backwards-incompatible – just less obvious about it.

Should fix CI failures in brianc/node-postgres’s pull requests (and on master if it were run again), and also fix #24.

Also fixes a bug where the Pool.prototype.connect callback would be called twice if there was an error.

This reverts commit 6a7edab.

The callback passed to `Pool.prototype.connect` should be responsible for handling connection errors. The `error` event is documented to be:

> Emitted whenever an idle client in the pool encounters an error.

This isn’t the case of an idle client in the pool; it never makes it into the pool.

It also breaks tests on pg’s master because of nonspecific dependencies.
It’s incorrect to do so. One consequence is that a rejected promise will be unhandled, which is currently annoying, but also dangerous in the future:

> DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

The way callbacks are used currently also causes brianc#24 (hiding of errors thrown synchronously from the callback). One fix for that would be to call them asynchronously from inside the `new Promise()` executor:

    process.nextTick(cb, error);

I don’t think it’s worth implementing, though, since it would still be backwards-incompatible – just less obvious about it.

Also fixes a bug where the `Pool.prototype.connect` callback would be called twice if there was an error.
@nomagick

nomagick commented Oct 28, 2016 •

Copy link
Copy Markdown
Contributor

I would +1 this feature but please don't revoke my error emition code.

Not in this PR at least.

@brianc

brianc commented Dec 4, 2016

Copy link
Copy Markdown
Owner

Thank you so much for this PR @charmander - sorry it took me a while to get to it. A bout of open source burnout as well as a long much needed vacation. :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pg-pool swallows errors

3 participants