Skip to content

Stack trace isn't returning all it should #8785

Closed

Description

@wanton7

Issue Description

TypeORM queries doesn't return stack trace that contains all it should if there error in a query.

Expected Behavior

it('test', async () => {
  await connection.query('select * foo');
});

This should return stack trace up to the test

Actual Behavior

But returns this even with Error.stackTraceLimit = 200; it return stack trace like this

 at QueryFailedError.TypeORMError [as constructor] (error/TypeORMError.ts:7:9)
    at new QueryFailedError (error/QueryFailedError.ts:9:9)
    at PostgresQueryRunner.<anonymous> (driver/postgres/PostgresQueryRunner.ts:247:19)
    at step (../node_modules/typeorm/node_modules/tslib/tslib.js:143:27)
    at Object.throw (../node_modules/typeorm/node_modules/tslib/tslib.js:124:57)
    at rejected (../node_modules/typeorm/node_modules/tslib/tslib.js:115:69)

Steps to Reproduce

import { Connection } from 'typeorm';

describe('Stack trace not returning all it should', () => {
  let connection: Connection;
  beforeAll(async () => {
    Error.stackTraceLimit = 200;
    connection = new Connection({
      type: 'postgres',
      host: 'localhost',
      port: 5432,
      username: 'postgres',
      password: 'postgres',
      database: 'testdb',
      entities: [],
      synchronize: true,
      logging: false,
    });
    await connection.connect();
  });

  afterAll(async () => {
    await connection.close();
  });

  it('should be defined', () => {
    expect(connection).toBeDefined();
  });

  it('test', async () => {
    await connection.query('select * foo');
  });
});

My Environment

Dependency Version
Operating System Windows 10
NestJS version 8.3.1
Node.js version 16.14.0
Typescript version 4.5.5
TypeORM version 0.2.42

Additional Context

Currently TypeORM version is coming from NestJS but I used it directly to produce this problem.

Relevant Database Driver(s)

DB Type Reproducible
aurora-mysql no
aurora-postgres no
better-sqlite3 no
cockroachdb no
cordova no
expo no
mongodb no
mysql no
nativescript no
oracle no
postgres yes
react-native no
sap no
sqlite no
sqlite-abstract no
sqljs no
sqlserver no

Are you 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 don't know how to start. I would need guidance.
  • ✖️ No, I don’t have the time, but I can support (using donations) development.
  • ✅ No, I don’t have the time and I’m okay to wait for the community / maintainers to resolve this issue.

Activity

  1. pleerock commented on Mar 23, 2022

    @pleerock
    Member

    Not sure if it's a bug, but anyway contributions are welcomed for this issue.

  2. wanton7 commented on Mar 23, 2022

    @wanton7
    Author

    Async stack trace aren't properly returned. These will be returned for unbroken async/await chains. Somewhere inside TypeORM this chain is broken. Lot harder to find problems in production coming from TypeORM if this is not fixed.

  3. pleerock commented on Mar 23, 2022

    @pleerock
    Member

    I can't imagine what code in TypeORM can lead to broken logging chains. If you think the problem comes from TypeORM code it's better to investigate and try to find it, otherwise... I guess this issue won't be ever resolved. Also, recommend to upgrade to 0.3.x since it outputs into es6 and clean async/await output - maybe it will solve your issue.

  4. wanton7 commented on Mar 23, 2022

    @wanton7
    Author

    Sadly our TypeORM version is coming from @nestjs/typeorm package. Because TypeORM isn't using semantic versioning at least yet I don't we can update it without breaking that package. But will try out never version of TypeORM in separate project.

  5. pleerock commented on Mar 23, 2022

    @pleerock
    Member

    I'm sure nestjs team will publish a new package version with updated dependencies very soon.

  6. Ginden commented on Mar 23, 2022

    @Ginden
    Contributor

    This is well known issue with TypeORM 0.2.*

    Unfortunately, new Promise, used through old code, doesn't leave nice stack traces.

  7. wanton7 commented on Mar 23, 2022

    @wanton7
    Author

    @Ginden Thank you very much for this information!

  8. added
    good first issue
    and removed on Apr 13, 2026
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

    good first issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions