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

fix: missing setContext when using logger: false #2243

Merged
merged 1 commit into from
Mar 27, 2023

Conversation

mikaellanger
Copy link

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

What is the current behavior?

HealthIndicator assumes it gets a ConsoleLogger, but TERMINUS_LOGGER is only guaranteed to be an instance of LoggerService which doesn't have a setContext method. This breaks when using logger: false.

[Nest] 1 - 03/20/2023, 7:37:21 AM ERROR [ExceptionHandler] this.logger.setContext is not a function
TypeError: this.logger.setContext is not a function
at new HttpHealthIndicator (/opt/app-root/src/.yarn/virtual/@nestjs-terminus-virtual-50e9f71c76/0/cache/@nestjs-terminus-npm-9.2.1-a0864fdc23-ac09b7fced.zip/node_modules/@nestjs/terminus/dist/health-indicator/http/http.health.js:60:21)
at Injector.instantiateClass (/opt/app-root/src/.yarn/unplugged/@nestjs-core-virtual-a42986c2d9/node_modules/@nestjs/core/injector/injector.js:351:19)
at callback (/opt/app-root/src/.yarn/unplugged/@nestjs-core-virtual-a42986c2d9/node_modules/@nestjs/core/injector/injector.js:56:45)
at async Injector.resolveConstructorParams (/opt/app-root/src/.yarn/unplugged/@nestjs-core-virtual-a42986c2d9/node_modules/@nestjs/core/injector/injector.js:136:24)
at async Injector.loadInstance (/opt/app-root/src/.yarn/unplugged/@nestjs-core-virtual-a42986c2d9/node_modules/@nestjs/core/injector/injector.js:61:13)
at async Injector.loadProvider (/opt/app-root/src/.yarn/unplugged/@nestjs-core-virtual-a42986c2d9/node_modules/@nestjs/core/injector/injector.js:88:9)
at async Injector.lookupComponentInImports (/opt/app-root/src/.yarn/unplugged/@nestjs-core-virtual-a42986c2d9/node_modules/@nestjs/core/injector/injector.js:281:17)
at async Injector.lookupComponentInParentModules (/opt/app-root/src/.yarn/unplugged/@nestjs-core-virtual-a42986c2d9/node_modules/@nestjs/core/injector/injector.js:245:33)
at async Injector.resolveComponentInstance (/opt/app-root/src/.yarn/unplugged/@nestjs-core-virtual-a42986c2d9/node_modules/@nestjs/core/injector/injector.js:200:33)
at async resolveParam (/opt/app-root/src/.yarn/unplugged/@nestjs-core-virtual-a42986c2d9/node_modules/@nestjs/core/injector/injector.js:120:38)

Same issue that was fixed in #2225 but for health-indicator/http

Issue Number: N/A

What is the new behavior?

Avoid crash by checking that logger is instance of ConsoleLogger before calling setContext

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

HealthIndicator assumes it gets a ConsoleLogger, but TERMINUS_LOGGER is only
guaranteed to be an instance of LoggerService which doesn't have a setContext
method. This breaks when using logger: false.
@BrunnerLivio BrunnerLivio merged commit c92a3c8 into nestjs:master Mar 27, 2023
@BrunnerLivio
Copy link
Member

Thanks, appreciate it ❤️
Released with v9.2.2 🎉

@mikaellanger
Copy link
Author

❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants