You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Stack trace is truncated in SQL Server query runner #11499
When queries fail with Sql Server, the stack trace is pointing to TypeOrm code
Expected Behavior
The stack trace should include the call site before typeorm.
Actual Behavior
The stack trace is terminated inside of the query runner code. Callbacks are resetting the stack.
Steps to reproduce
Set up a Sql Server environment
Create a query runner and perform an invalid query.
Observe the stack trace in the thrown error.
[Nest] 93661 - 05/28/2025, 7:13:42 AM ERROR [ExceptionsHandler] QueryFailedError: Error: Cannot insert the value NULL into column 'YYY', table 'XXX'; column does not allow nulls. INSERT fails.
at (/snip/node_modules/typeorm/driver/src/driver/sqlserver/SqlServerQueryRunner.ts:277:30)
at /snip/node_modules/mssql/lib/base/request.js:440:25
at Request.userCallback (/snip/node_modules/mssql/lib/tedious/request.js:492:15)
at Request.Request.callback (/snip/node_modules/tedious/src/request.ts:379:14)
at onEndOfMessage (/snip/node_modules/tedious/src/connection.ts:3755:22)
My Environment
Dependency
Version
Node.js version
20.16
Typescript version
5.8.3
TypeORM version
0.3.24
Additional Context
Related to #11271 - just SQL Server instead of MySQL. May well affect other drivers too.
Relevant Database Driver(s)
aurora-mysql
aurora-postgres
better-sqlite3
cockroachdb
cordova
expo
mongodb
mysql
nativescript
oracle
postgres
react-native
sap
spanner
sqlite
sqlite-abstract
sqljs
sqlserver
Are you willing to resolve this issue by submitting a Pull Request?
which appears to align with the strategy in the MySQL PR: #11273 (albeit that PR had additional changes to promisify the underlying query call whereas that was already in place for the SqlServer driver)
Let me know if you'd like a PR along similar lines.
Activity
jamescrowley commentedon May 28, 2025
FYI I've been able to resolve this issue locally by simply moving the wrapping of err with QueryFailedError to the outer try/catch and throwing it:
(jamescrowley/typeorm@master...patch-stack-trace)
which appears to align with the strategy in the MySQL PR: #11273 (albeit that PR had additional changes to promisify the underlying query call whereas that was already in place for the SqlServer driver)
Let me know if you'd like a PR along similar lines.
pkuczynski commentedon Nov 17, 2025
Sounds like a good idea. Would you like to throw a PR?