Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error cause is not logged in dev:watch mode #2533

Open
3 of 15 tasks
dmitryrn opened this issue Feb 27, 2024 · 1 comment
Open
3 of 15 tasks

Error cause is not logged in dev:watch mode #2533

dmitryrn opened this issue Feb 27, 2024 · 1 comment

Comments

@dmitryrn
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

I change tsconfig.json target to ES2022

I throw an error in onModuleInit in a service:

    onModuleInit() {
        try {
            this.method()
        } catch (error) {
            throw new Error('test 123', { cause: error })
        }
    }

    method() {
        throw new Error('cause 456')
    }

I run: nest start --watch

In the terminal I see that the cause is not logged:

[1:27:41 PM] Starting compilation in watch mode...

[1:27:41 PM] Found 0 errors. Watching for file changes.

[Nest] 465258  - 02/27/2024, 1:27:42 PM     LOG [NestFactory] Starting Nest application...
[Nest] 465258  - 02/27/2024, 1:27:42 PM     LOG [InstanceLoader] AppModule dependencies initialized +5ms
[Nest] 465258  - 02/27/2024, 1:27:42 PM     LOG [RoutesResolver] AppController {/}: +3ms
[Nest] 465258  - 02/27/2024, 1:27:42 PM     LOG [RouterExplorer] Mapped {/, GET} route +1ms

/home/user/projects/repro/src/app.controller.ts:12
            throw new Error('test 123', { cause: error })
                  ^
Error: test 123
    at AppController.onModuleInit (/home/user/projects/repro/src/app.controller.ts:12:19)
    at MapIterator.iteratee (/home/user/projects/repro/node_modules/@nestjs/core/hooks/on-module-init.hook.js:22:43)
    at MapIterator.next (/home/user/projects/repro/node_modules/iterare/src/map.ts:9:39)
    at IteratorWithOperators.next (/home/user/projects/repro/node_modules/iterare/src/iterate.ts:19:28)
    at Function.from (<anonymous>)
    at IteratorWithOperators.toArray (/home/user/projects/repro/node_modules/iterare/src/iterate.ts:227:22)
    at callOperator (/home/user/projects/repro/node_modules/@nestjs/core/hooks/on-module-init.hook.js:23:10)
    at callModuleInitHook (/home/user/projects/repro/node_modules/@nestjs/core/hooks/on-module-init.hook.js:43:23)
    at NestApplication.callInitHook (/home/user/projects/repro/node_modules/@nestjs/core/nest-application-context.js:223:50)
    at NestApplication.init (/home/user/projects/repro/node_modules/@nestjs/core/nest-application.js:100:9)
^C

When I run nest build and then node dist/main, I have the expected stack trace:

> repro@0.0.1 build
> nest build


> repro@0.0.1 start:prod
> node dist/main

[Nest] 465382  - 02/27/2024, 1:27:45 PM     LOG [NestFactory] Starting Nest application...
[Nest] 465382  - 02/27/2024, 1:27:45 PM     LOG [InstanceLoader] AppModule dependencies initialized +5ms
[Nest] 465382  - 02/27/2024, 1:27:45 PM     LOG [RoutesResolver] AppController {/}: +4ms
[Nest] 465382  - 02/27/2024, 1:27:45 PM     LOG [RouterExplorer] Mapped {/, GET} route +1ms
/home/user/projects/repro/dist/app.controller.js:25
            throw new Error('test 123', { cause: error });
                  ^

Error: test 123
    at AppController.onModuleInit (/home/user/projects/repro/dist/app.controller.js:25:19)
    at MapIterator.iteratee (/home/user/projects/repro/node_modules/@nestjs/core/hooks/on-module-init.hook.js:22:43)
    ... 6 lines matching cause stack trace ...
    at NestApplication.callInitHook (/home/user/projects/repro/node_modules/@nestjs/core/nest-application-context.js:223:50)
    at async NestApplication.init (/home/user/projects/repro/node_modules/@nestjs/core/nest-application.js:100:9) {
  [cause]: Error: cause 456
      at AppController.method (/home/user/projects/repro/dist/app.controller.js:29:15)
      at AppController.onModuleInit (/home/user/projects/repro/dist/app.controller.js:22:18)
      at MapIterator.iteratee (/home/user/projects/repro/node_modules/@nestjs/core/hooks/on-module-init.hook.js:22:43)
      at MapIterator.next (/home/user/projects/repro/node_modules/iterare/lib/map.js:13:39)
      at IteratorWithOperators.next (/home/user/projects/repro/node_modules/iterare/lib/iterate.js:21:28)
      at Function.from (<anonymous>)
      at IteratorWithOperators.toArray (/home/user/projects/repro/node_modules/iterare/lib/iterate.js:180:22)
      at callOperator (/home/user/projects/repro/node_modules/@nestjs/core/hooks/on-module-init.hook.js:23:10)
      at callModuleInitHook (/home/user/projects/repro/node_modules/@nestjs/core/hooks/on-module-init.hook.js:43:23)
      at NestApplication.callInitHook (/home/user/projects/repro/node_modules/@nestjs/core/nest-application-context.js:223:50)
}

Node.js v21.6.2

Minimum reproduction code

https://github.com/dmitryrn/nestrepro

Steps to reproduce

clone the reproduction code;
run npm run start:dev;
see that error's cause is not logged;
run npm run build && npm run start:prod;
see that error's cause is logged.

Expected behavior

Seeing an error cause while in nest start --watch mode

Package

  • I don't know. Or some 3rd-party package
  • @nestjs/common
  • @nestjs/core
  • @nestjs/microservices
  • @nestjs/platform-express
  • @nestjs/platform-fastify
  • @nestjs/platform-socket.io
  • @nestjs/platform-ws
  • @nestjs/testing
  • @nestjs/websockets
  • Other (see below)

Other package

No response

NestJS version

^10.0.0

Packages versions

    "@nestjs/common": "^10.0.0",
    "@nestjs/config": "^3.2.0",
    "@nestjs/core": "^10.0.0",
    "@nestjs/platform-express": "^10.0.0",
    "@nestjs/cli": "^10.0.0",
    "@nestjs/schematics": "^10.0.0",
    "@nestjs/testing": "^10.0.0",

    "typescript": "^5.1.3"

Node.js version

v21.6.2

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

While I was creating a reproduction repo, I realized that since you have ES2021 in your default tsconfig.json, that means you don't have to support ES2022. But still it would be nice to have error's cause to be logged.

@kamilmysliwiec
Copy link
Member

Would you like to create a PR for this issue?

@kamilmysliwiec kamilmysliwiec transferred this issue from nestjs/nest Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants