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

Improve error handling for failed connections #55

Open
richardsimko opened this issue Oct 5, 2016 · 2 comments
Open

Improve error handling for failed connections #55

richardsimko opened this issue Oct 5, 2016 · 2 comments

Comments

@richardsimko
Copy link

Currently only the following stack trace is printed when the connection fails

{projectBasePath}/node_modules/jugglingdb-postgres/lib/postgres.js:419
        data.forEach(function(field){
            ^

TypeError: Cannot read property 'forEach' of undefined
    at decoratedCallback ({projectBasePath}/node_modules/jugglingdb-postgres/lib/postgres.js:419:13)
    at {projectBasePath}/node_modules/jugglingdb-postgres/lib/postgres.js:64:20
    at {projectBasePath}/node_modules/jugglingdb-postgres/node_modules/pg/lib/pool.js:75:25
    at {projectBasePath}/node_modules/jugglingdb-postgres/node_modules/generic-pool/lib/generic-pool.js:274:11
    at {projectBasePath}/node_modules/jugglingdb-postgres/node_modules/pg/lib/pool.js:27:26
    at null.<anonymous> ({projectBasePath}/node_modules/jugglingdb-postgres/node_modules/pg/lib/client.js:181:5)
    at emitOne (events.js:77:13)/
    at emit (events.js:169:7)
    at Socket.<anonymous> ({projectBasePath}/node_modules/jugglingdb-postgres/node_modules/pg/lib/connection.js:59:10)
    at emitOne (events.js:77:13)
    at Socket.emit (events.js:169:7)
    at emitErrorNT (net.js:1269:8)
    at nextTickCallbackWith2Args (node.js:442:9)
    at process._tickCallback (node.js:356:17)

At that point in the code (postgres.js:419) an error object is available and should be used to convey errors to the user.

Same goes if the connection is suddenly broken it will print the following error and crash the app:

events.js:141
      throw er; // Unhandled 'error' event
      ^

error: terminating connection due to administrator command
    at Connection.parseE ({projectBasePath}/node_modules/jugglingdb-postgres/node_modules/pg/lib/connection.js:534:11)
    at Connection.parseMessage ({projectBasePath}/node_modules/jugglingdb-postgres/node_modules/pg/lib/connection.js:361:17)
    at Socket.<anonymous> ({projectBasePath}/node_modules/jugglingdb-postgres/node_modules/pg/lib/connection.js:105:22)
    at emitOne (events.js:77:13)
    at Socket.emit (events.js:169:7)
    at readableAddChunk (_stream_readable.js:153:18)
    at Socket.Readable.push (_stream_readable.js:111:10)
    at TCP.onread (net.js:536:20)

I suggest providing a more stable way of dealing with errors, such as a number of connection retries followed by a graceful error message if the retries fail.

@1602
Copy link
Contributor

1602 commented Oct 5, 2016

Thanks for reporting this, unfortunately this project is half-rewritten (not committed yet) and stuck in that state for a while, because i have to time to support it now. I have no hope for finding any time for it soon.

@richardsimko
Copy link
Author

Got it, thanks for your fast reply.

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

No branches or pull requests

2 participants