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

feat(core): enhance circular dependency error message #9506

Merged

Conversation

ntibi
Copy link
Contributor

@ntibi ntibi commented Apr 29, 2022

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?

when trying to insert an undefined provider (due to a circular dependency), you get this message

A circular dependency has been detected. Please, make sure that each side of a bidirectional relationships are decorated with "forwardRef()".,

Issue Number: N/A

What is the new behavior?

if the module you are inserting the provider into is defined, you get the module name in the error (hinting where to look for to find the circular dependency)

A circular dependency has been detected in TheModule. Please, make sure that each side of a bidirectional relationships are decorated with "forwardRef()".,

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@micalevisk
Copy link
Member

I believe the message will be
A circular dependency has been detected inside TheModule. Please, make sure that each side of a bidirectional relationships are decorated with "forwardRef()".

@kamilmysliwiec
Copy link
Member

Could you share a minimum reproduction repository that showcases the exact scenario this PR improves?

@ntibi
Copy link
Contributor Author

ntibi commented May 7, 2022

@kamilmysliwiec just having an undefined provider (to simulate the circular dependency) is enough to reproduce the scenario

import { NestFactory } from '@nestjs/core';
import { Module } from '@nestjs/common';

const provider = undefined; // not set because of a circular dependency

@Module({
  providers: [provider],
})
export class App {}

NestFactory.create(App).then(app => app.listen(3000))

upstream:

nest start
[Nest] 1402850 - 05/08/2022, 1:35:15 AM LOG [NestFactory] Starting Nest application...
[Nest] 1402850 - 05/08/2022, 1:35:15 AM ERROR [ExceptionHandler] A circular dependency has been detected. Please, make sure that each side of a bidirectional relationships are decorated with "forwardRef()".

this branch:

nest start
[Nest] 1404399 - 05/08/2022, 1:35:16 AM LOG [NestFactory] Starting Nest application...
[Nest] 1404399 - 05/08/2022, 1:35:16 AM ERROR [ExceptionHandler] A circular dependency has been detected inside App. Please, make sure that each side of a bidirectional relationships are decorated with "forwardRef()".

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

Successfully merging this pull request may close these issues.

None yet

5 participants