Skip to content

refactor(core): include DI path into cyclic dependency error message#50902

Closed
JeanMeche wants to merge 7 commits intoangular:mainfrom
JeanMeche:feat/circle-deps
Closed

refactor(core): include DI path into cyclic dependency error message#50902
JeanMeche wants to merge 7 commits intoangular:mainfrom
JeanMeche:feat/circle-deps

Conversation

@JeanMeche
Copy link
Copy Markdown
Member

@JeanMeche JeanMeche commented Jun 30, 2023

This commit updates the logic to better handle a situation when there is a cyclic DI dependency detected. Previously, the error message used to contain the name of the token that triggered the problem. With this change, the DI resolution path would also be included, so that it's easier to find and resolve the cycle.

I'd like to credit @AndrewKushnir who did most of the work on this.

Fixes: #46189

@JeanMeche JeanMeche force-pushed the feat/circle-deps branch 5 times, most recently from fb181b7 to 17ac2cc Compare July 1, 2023 13:38
@JeanMeche JeanMeche changed the title fix(core): include DI path into cyclic dependency error message refactor(core): include DI path into cyclic dependency error message Jul 1, 2023
@JeanMeche JeanMeche marked this pull request as ready for review July 1, 2023 14:30
@pullapprove pullapprove bot requested a review from crisbeto July 1, 2023 14:30
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a better way to retrieve the name of the class ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also a bit sensitive to the compiler output. It looks like we construct the NodeInjectorFactory in these places:

  1. In configureViewWithDirective we should be able to capture the name from the directive def.
  2. The two calls in resolveProvider might have access to it through the DI token. It's not guaranteed, but we can fall back to something like <unknown> or <anonymous>.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you suggesting something like ?

if(factory.factory.name) {
  name = factory.factory.name.slice(0, -8)
} else {
  name = 'unknown' 
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I mean that we try to capture the name when constructing the NodeInjectorFactory and then fall back to something like unknown.

@pkozlowski-opensource pkozlowski-opensource added action: review The PR is still awaiting reviews from at least one requested reviewer area: core Issues related to the framework runtime labels Jul 5, 2023
@ngbot ngbot bot added this to the Backlog milestone Jul 5, 2023
@JeanMeche JeanMeche force-pushed the feat/circle-deps branch 3 times, most recently from 00468eb to 539fbb2 Compare August 8, 2023 21:06
@AndrewKushnir AndrewKushnir modified the milestones: Backlog, v17-candidates Sep 1, 2023
@AndrewKushnir AndrewKushnir added the target: major This PR is targeted for the next major release label Oct 6, 2023
@AndrewKushnir
Copy link
Copy Markdown
Contributor

@JeanMeche could you please rebase this PR when you get a chance? We'll perform code review and see if we can land it in v17. Thank you.

@AndrewKushnir
Copy link
Copy Markdown
Contributor

Exploratory presubmit.

@AndrewKushnir AndrewKushnir removed this from the v17-final milestone Nov 9, 2023
@JeanMeche JeanMeche force-pushed the feat/circle-deps branch 3 times, most recently from 0cafc1f to 9798e85 Compare July 3, 2025 12:11
@JeanMeche JeanMeche requested review from AndrewKushnir and removed request for AndrewKushnir July 3, 2025 12:50
@AndrewKushnir AndrewKushnir removed their assignment Jul 3, 2025
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also a bit sensitive to the compiler output. It looks like we construct the NodeInjectorFactory in these places:

  1. In configureViewWithDirective we should be able to capture the name from the directive def.
  2. The two calls in resolveProvider might have access to it through the DI token. It's not guaranteed, but we can fall back to something like <unknown> or <anonymous>.

AndrewKushnir and others added 2 commits July 4, 2025 11:30
This commit updates the logic to better handle a situation when there is a cyclic DI dependency detected. Previously, the error message used to contain the name of the token that triggered the problem. With this change, the DI resolution path would also be included, so that it's easier to find and resolve the cycle.
@JeanMeche JeanMeche removed this from the v18 feature freeze candidates milestone Jul 8, 2025
@ngbot ngbot bot added this to the Backlog milestone Jul 8, 2025
@JeanMeche
Copy link
Copy Markdown
Member Author

TESTED=TGP

@JeanMeche JeanMeche added target: patch This PR is targeted for the next patch release and removed target: major This PR is targeted for the next major release labels Jul 10, 2025
@AndrewKushnir AndrewKushnir added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Jul 10, 2025
@AndrewKushnir
Copy link
Copy Markdown
Contributor

This PR was merged into the repository by commit 96014b5.

The changes were merged into the following branches: main, 20.1.x

AndrewKushnir added a commit that referenced this pull request Jul 10, 2025
…50902)

This commit updates the logic to better handle a situation when there is a cyclic DI dependency detected. Previously, the error message used to contain the name of the token that triggered the problem. With this change, the DI resolution path would also be included, so that it's easier to find and resolve the cycle.

PR Close #50902
@JeanMeche JeanMeche deleted the feat/circle-deps branch July 10, 2025 21:32
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker area: core Issues related to the framework runtime target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve error message for "No provider for" errors.

4 participants