Fixed bug that prevents constraints violations to fire "query-failed" events #460
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The bug is best described in #459.
When reading the code to find the bug's origin I found that event firing was not tested at all. So I added tests for all global events.
Then, I found where the bug was coming from: the method
DbSchema.prepare()is the place in the codebase that raises global events. This seems right since when a query is executed, it eventually gets prepared. The problem is that if the query does not fail to get prepared but it does fail when executed, the error is not catched thus the "query-failed" event is not risen.To fix this issue, I simply moved up the try/catch to the
DbSchema.query()method:With this change, when a query fails to be executed, the "query-failed" event fires too.