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

Gracefully handling connections errors... #405

Open
asleepinglion opened this issue May 25, 2014 · 1 comment
Open

Gracefully handling connections errors... #405

asleepinglion opened this issue May 25, 2014 · 1 comment

Comments

@asleepinglion
Copy link

Maybe I'm missing something, but since the instantiation of the Schema class automatically does the connect behind the scenes without a callback, there is no way to gracefully handle connection errors.

Most other ORMs seem to provide a connect function with a callback that passes back an err object, as is the case when you perform a find operation with JugglingDB. If for some reason the server is unable to connect I want to gracefully handle the error and not kill the process. I could use Node's domains to catch the error, but it would be so much simpler to just have a callback. I see there is an event emitted when JugglingDB has connected, but other than that, what am I supposed to do? I rather like the this ORM (minus the thorough documentation), but this seems like a simple thing thats missing?

@asleepinglion
Copy link
Author

After posting a question about proper ways to handle errors with this as a specific example to Stack Overflow: Understanding Try/Catch and Domains for Error Handling in Node; I was shown that when pooling is turned off (using the mysql adapter), JugglingDB logs the error and retries the connection. This is certainly better behavior, but honestly I feel like it should still emit or return the error via a callback so I can handle things my own way, just like any other ORM.

That said, when pooling is turned on, catchable errors are thrown when they should be returned via callback or emitted. See the following stack trace:


Error: connect ECONNREFUSED
    at errnoException (net.js:901:11)
    at Object.afterConnect [as oncomplete] (net.js:892:19)
    --------------------
    at Protocol._enqueue /Sites/site/node_modules/jugglingdb-mysql/node_modules/mysql/lib/protocol/Protocol.js:110:48)
    at Protocol.handshake (/Sites/site/node_modules/jugglingdb-mysql/node_modules/mysql/lib/protocol/Protocol.js:42:41)
    at PoolConnection.Connection.connect (/Sites/site/node_modules/jugglingdb-mysql/node_modules/mysql/lib/Connection.js:101:18)
    at Pool.getConnection (/Sites/site/node_modules/jugglingdb-mysql/node_modules/mysql/lib/Pool.js:42:23)
    at Pool.query (/Sites/site/node_modules/jugglingdb-mysql/node_modules/mysql/lib/Pool.js:185:8)
    at initDatabase (/Sites/site/node_modules/jugglingdb-mysql/lib/mysql.js:62:20)
    at initializeConnection (/Sites/site/node_modules/jugglingdb-mysql/lib/mysql.js:49:9)
    at Object.initializeSchema [as initialize] (/Sites/site/node_modules/jugglingdb-mysql/lib/mysql.js:33:5)
    at new Schema (/Sites/site/node_modules/jugglingdb/lib/schema.js:105:13)
    at Application.loadConnections (/Sites/site/core/application.js:95:40)

Process finished with exit code 8

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

1 participant