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

Log is not auto-flushed on error during initialization #13400

Closed
3 of 15 tasks
egs-cm opened this issue Apr 5, 2024 · 1 comment · May be fixed by #13405
Closed
3 of 15 tasks

Log is not auto-flushed on error during initialization #13400

egs-cm opened this issue Apr 5, 2024 · 1 comment · May be fixed by #13405
Labels
needs triage This issue has not been looked into

Comments

@egs-cm
Copy link

egs-cm commented Apr 5, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

When option bufferLogs is enabled, logs are not flushed on error during app initialization. Passing autoFlushLogs: true does not change the behavior. The application closes without a message, exit value of node process is 1.

The error is displayed correctly, when option bufferLogs is disabled.

Probable cause:
this.autoFlushLogs is not passed (compare call to asyncRun).

private createExceptionZone(
    receiver: Record<string, any>,
    prop: string,
  ): Function {
    const teardown = this.abortOnError === false ? rethrow : undefined;

    return (...args: unknown[]) => {
      let result: unknown;
      ExceptionsZone.run(() => {
        result = receiver[prop](...args);
      }, teardown);

      return result;
    };
  }

https://github.com/nestjs/nest/blob/8b4dbb30909be86290d01da54205ab4bf081ab46/packages/core/nest-factory.ts#L264C3-L278C4

Minimum reproduction code

https://stackblitz.com/edit/nestjs-typescript-starter-1y1fvy?file=src%2Fmain.ts

Steps to reproduce

nest start

Expected behavior

The following error should be displayed:

[Nest] 23  - 05/04/2024, 09:05:23   ERROR [ExceptionHandler] Nest could not find AppService element (this provider does not exist in the current context)
Error: Nest could not find AppService element (this provider does not exist in the current context)
    at RuntimeException (/home/projects/nestjs-typescript-starter-1y1fvy/node_modules/@nestjs/core/errors/exceptions/runtime.exception.js:6:9)
    at UnknownElementException (/home/projects/nestjs-typescript-starter-1y1fvy/node_modules/@nestjs/core/errors/exceptions/unknown-element.exception.js:8:9)
    at get (/home/projects/nestjs-typescript-starter-1y1fvy/node_modules/@nestjs/core/injector/instance-links-host.js:15:19)
    at find (/home/projects/nestjs-typescript-starter-1y1fvy/node_modules/@nestjs/core/injector/abstract-instance-resolver.js:8:60)
    at get (/home/projects/nestjs-typescript-starter-1y1fvy/node_modules/@nestjs/core/nest-application-context.js:70:20)
    at createExceptionZone/</< (/home/projects/nestjs-typescript-starter-1y1fvy/node_modules/@nestjs/core/nest-factory.js:145:40)
    at run (/home/projects/nestjs-typescript-starter-1y1fvy/node_modules/@nestjs/core/errors/exceptions-zone.js:10:13)
    at createExceptionZone/< (/home/projects/nestjs-typescript-starter-1y1fvy/node_modules/@nestjs/core/nest-factory.js:144:46)
    at get/< (/home/projects/nestjs-typescript-starter-1y1fvy/node_modules/@nestjs/core/nest-factory.js:193:54)
    at bootstrap (/home/projects/nestjs-typescript-starter-1y1fvy/src/main.ts:7:19)

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.3.7

Packages versions

[Nest CLI]
Nest CLI Version : 10.3.2 

[Nest Platform Information]
platform-express version : 10.3.7
microservices version    : 10.3.7
schematics version       : 10.1.1
swagger version          : 7.3.1
testing version          : 10.3.7
common version           : 10.3.7
config version           : 3.2.1
axios version            : 3.0.2
core version             : 10.3.7
cli version              : 10.3.2

Node.js version

v18.18.2

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

@egs-cm egs-cm added the needs triage This issue has not been looked into label Apr 5, 2024
@kamilmysliwiec
Copy link
Member

Let's track this here #13405

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage This issue has not been looked into
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants