Sequelize errors don't print properly in jest
See original GitHub issueIssue Creation Checklist
- I understand that my issue will be automatically closed if I don’t fill in the requested information
- I have read the contribution guidelines
Bug Description
When using sequelize in jest, errors don’t print their message, which makes debugging difficult. You get a trace back into the query interface in sequelize, but you have to set breakpoints in sequelize in order to determine the nature of the error (syntax error, foreign key constraint issue, etc.).
I have verified that other thrown errors print properly, so it seems to be an issue with these in particular in Sequelize.
Reproducible Example
it("passes", async () => {
await db.query("SELECT 1 )").
});
In this example, let’s assume I want to write a test that selects 1 and passes. Assuming db is a Sequelize instance pointing at a postgres db, this test that we want to be successful fails due to a syntax error. In the console, I get a trace, but the error message is missing.
What do you expect to happen?
The error message prints indicating the sql syntax error. The full printout should look someting like:
DatabaseError: syntax error at or near ")"
at Query.run (../node_modules/sequelize/src/dialects/postgres/query.js:76:25)
at ../node_modules/sequelize/src/sequelize.js:641:28
at PostgresQueryInterface.select (../node_modules/sequelize/src/dialects/abstract/query-interface.js:1001:12)
at … remaining trace back to test
What is actually happening?
The error is printed, but only the stack trace appears, which will look something like this (note that message is omitted):
at Query.run (../node_modules/sequelize/src/dialects/postgres/query.js:76:25)
at ../node_modules/sequelize/src/sequelize.js:641:28
at PostgresQueryInterface.select (../node_modules/sequelize/src/dialects/abstract/query-interface.js:1001:12)
at … remaining trace back to test
Environment
- Sequelize version: 6.21.3
- Node.js version: 16.15.0
- If TypeScript related: TypeScript version:
- Database & Version: Postgres 11.x
- Connector library & Version: pg@8.7.3
Would you be willing to resolve this issue by submitting a Pull Request?
- Yes, I have the time and I know how to start.
- Yes, I have the time but I will need guidance.
- No, I don’t have the time, but my company or I are supporting Sequelize through donations on OpenCollective.
- No, I don’t have the time, and I understand that I will need to wait until someone from the community or maintainers is interested in resolving my issue.
Indicate your interest in the resolution of this issue by adding the 👍 reaction. Comments such as “+1” will be removed.
Issue Analytics
- State:
- Created a year ago
- Reactions:19
- Comments:16 (7 by maintainers)
We should fix this issue in all environments, it’s a problem in mocha and other tools that only print the
.stack
propertyFollowing #13347, the stack went from
To
But it should have become this instead:
It should merge both stacks (keeping the error message but replacing the trace) instead of fully replacing it.
What are other programmers doing to debug errors while Jest isn’t reporting them correctly? My portfolio project is held up due to this bug … need my portfolio project done fast
edit: I discovered that I could get the truncated error message to print in full by surrounding my Sequelize code with
Had to do it in like 40 places to find the right one but, I got it! Hope this helps someone