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

Errors are not logged through custom logger #1121

Open
3 of 7 tasks
coler-j opened this issue Apr 22, 2024 · 2 comments
Open
3 of 7 tasks

Errors are not logged through custom logger #1121

coler-j opened this issue Apr 22, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@coler-j
Copy link

coler-j commented Apr 22, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

When an error is raised

  1. I am not recieving it within my errorHandler
  2. The error output is not using the custom logger I have injected following Change CommandFactory in order to be able to access the INestApplicationContext before runner execution. #852

My output will be like:

Error: TEST[22:09:29.800] INFO (21106): Starting Nest application...
    context: "NestFactory"
[22:09:29.800] INFO (21106): CommandRootModule dependencies initialized
    context: "InstanceLoader"
[22:09:29.800] INFO (21106): AppModule dependencies initialized
    context: "InstanceLoader"
[22:09:29.800] INFO (21106): InstrumentationModule dependencies initialized
    context: "InstanceLoader"
[22:09:29.800] INFO (21106): OpenTelemetryModule dependencies initialized
    context: "InstanceLoader"
..... more logs

The output starts with the error Error: TEST which is not formatted as it should be with my logger, and then the buffered logs continue afterwards...

Minimum reproduction code

Command that returns an error

import { Logger } from '@nestjs/common';
import { Command, CommandRunner } from 'nest-commander';

@Command({
  name: 'test', 
})
export class SomeCommand extends CommandRunner {
  private readonly logger = new Logger(SomeCommand.name);

  async run(inputs: string[], options: Record<string, unknown>): Promise<void> {
    this.logger.log(inputs);
    this.logger.log(options);
    await Promise.resolve();
    throw new Error('TEST');
  }
}

Expected behavior

Error is written with custom logger

Package

  • nest-commander
  • nest-commander-schematics
  • nest-commander-testing

Package version

3.12.5

Node.js version

20.11.1

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

@coler-j coler-j added the bug Something isn't working label Apr 22, 2024
@coler-j
Copy link
Author

coler-j commented Apr 22, 2024

What is the difference between serviceErrorHandler and errorHandler

@jmcdo29
Copy link
Owner

jmcdo29 commented Apr 22, 2024

serviceErrorHandler was created to handle errors that happen during this.commander.parseAsync as detailed in this PR, whereas errorHandler is the general commander error handler and modifies how errors at the commander level are handled

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants