Skip to content

Conversation

@nachovigilante
Copy link

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:

query(text: QueryOrAst): QueryResult {
        try {
            return this.prepare(text)
                .bind()
                .executeAll();
        } catch (e) {
            this.db.raiseGlobal('query-failed', text);
            throw e;
        }
    }

With this change, when a query fails to be executed, the "query-failed" event fires too.

There was a bug that prevented constraint violations from firing "query-failed" event. The problem was that in `query` method (line 62), the errors throwed by `.executeAll()` were not being catched. Due to this problem, the only errors that fired the "query-failed" event were the ones occuring inside the `prepare` method.
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

Successfully merging this pull request may close these issues.

1 participant