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
Add Connection Specific Errors #2576
Add Connection Specific Errors #2576
Conversation
…anager for MySQL to utilize these errors.
…n manager to use the new errors.
…rs so they aren't breaking up the grouping.
…Added tests for the errors.
Code looks good, however, some of the tests fail This test https://github.com/sequelize/sequelize/blob/master/test/sequelize.test.js#L121 should probably just be changed to something like |
* @constructor | ||
*/ | ||
error.ConnectionTimedOutError = function (parent) { | ||
error.ConnectionTimedOutError.call(this, parent); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error is calling it self, which results in a stack overflow (also applies to some of the other errors
… is propagated from the connection failure. As pointed out in the [PR](#2576 (comment)) for this functionality we would ideally not be checking error messages and instead be checking the constructors of the objects to make sure that they are an instance of the correct error type. There's some issues right now with two different constructors being used and not being able to use `instanceof`. We could fall back to the constructor name or some other check, but at the end of the day that isn't really any better than just checking the message.
@janmeier I went through and toyed with it some to change the tests to instead check the types that would be returned but I ran into a few issues. It looks like the constructor being used to create the Errors is a different instance from that which is available within the Tests which is causing I'm unfamiliar with the composition of Sequelize and I don't know if you've already ran into this problem (or if I'm doing something wrong based on your current setup). So instead for the time being I just updated the error message checks to match what is returned from the connection failure. If you have some suggestions or a concrete example of where this is used with Sequelize I'd be more than glad to revisit it and update the tests. |
@@ -19,7 +19,7 @@ describe(Support.getTestDialectTeaser("Configuration"), function() { | |||
|
|||
var seq = new Sequelize(config[dialect].database, config[dialect].username, config[dialect].password, {storage: '/path/to/no/where/land', logging: false, host: '0.0.0.1', port: config[dialect].port, dialect: dialect}) | |||
seq.query('select 1 as hello').error(function(err) { | |||
expect(err.message).to.match(/Failed to find (.*?) Please double check your settings\./) | |||
expect(err.message).to.match(/connect EINVAL/) | |||
done() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the done callback from the function and do
return expect(seq.query('select 1 as hello')).to.eventually.be.rejectedWith(seq.InvalidConnectionError, 'connect EINVAL');
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I'll get those updated.
For reference https://github.com/domenic/chai-as-promised/blob/master/test/should-promise-specific.coffee Also, I noticed that some of the tests in configuration.test are PG only - do they pass for mysql also now? |
case 'ECONNREFUSED': | ||
reject(new sequelizeErrors.ConnectionRefusedError(err)); | ||
break; | ||
case 'ER_ACCESS_D2ENIED_ERROR': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will never trigger because of the 2
- it was because we couldn't reliably catch the error at the time the codewas written as far as I rememeber - perhaps we can now?
Ping @DavidTPate Just need those tests updated, and maybe you can also address my other comment about access denied :)? |
@janmeier Will do, just been a busy time around the office so I haven't had a chance. |
…r checking and also checking the actual type of error thrown.
…y match if able.
…gres native to see if they are passing now.
…the ConnectionError constructor so that it can handle a falsey error object being sent as a parameter. Update the configuration tests to support SQLite and it's custom messages as well as the lack of authentication.
@janmeier All the tests are updated and look to be good. I removed the PG only restrictions and they are all working as expected as well. To the |
@@ -104,7 +104,7 @@ describe(Support.getTestDialectTeaser("Sequelize"), function () { | |||
}) | |||
}) | |||
|
|||
it('triggers the actual adapter error', function(done) { | |||
it.only('triggers the actual adapter error', function(done) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Woops :)
@DavidTPate Looks good - However you accidentally added an Weird that you had to call notify to get it working. Did you remove the done callback completely, so the function takes no args? |
@janmeier I didn't remove the Looks like an issue with |
@DavidTPate Everything that comes from a chain of |
An issue to say the least - a segfault :O ... |
…usly running for MariaDB to try and narrow down the issue.
…t to do flow control on it...
@janmeier I added the restrictions for those 2 methods that used to be PG only to not run for MariaDB (still runs for everything else) and everything went off without a hitch. I'm still not sure what the root cause of it is, but this brings it to the same state of testing as it was before my updates, should that be addressed in a separate issue? |
…lure-errors Add Connection Specific Errors
Solid work @DavidTPate ! |
You're very welcome to continue to debug the two mariadb errors in a separate issue :) |
This PR was created to address #2567, it adds new error constructors related specifically to connections. Each constructor inherits from the newly created
ConnectionError
constructor which inherits from theBaseError
constructor. It is created in the same vein as the errors emitted from MySQL Queries. Only the errors related to connections were wrapped, there are some unrelated ones within the Connection Managers (such as checking that the required dialect package is installed) which I did not modify.