Skip to content

Stack trace is truncated in SQL Server query runner #11499

Closed

Description

@jamescrowley

Issue description

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?

Yes, I have the time, and I know how to start.

Activity

  1. jamescrowley commented on May 28, 2025

    @jamescrowley
    Author

    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.

  2. pkuczynski commented on Nov 17, 2025

    @pkuczynski
    Member

    Sounds like a good idea. Would you like to throw a PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions