Do not fatal when a shorthand service class cannot be loaded - #1023
Open
mglaman wants to merge 2 commits into
Open
Do not fatal when a shorthand service class cannot be loaded#1023mglaman wants to merge 2 commits into
mglaman wants to merge 2 commits into
Conversation
class_exists() on a shorthand service ID autoloads the class. PHP resolves parent classes at declaration time, so a service class extending a class from an unavailable module throws an Error that killed the bootstrap before analysis started. Catch the Throwable and skip the service instead. Also skip decorator registration when the decorating service was dropped. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Symfony removes the decorating service from the container when the decorated service does not exist and decoration_on_invalid is set to ignore. Drop it from the service map to match the runtime container. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Owner
Author
|
Pushed a second commit that respects |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Service map generation calls
class_exists()on shorthand service IDs (added in #817).class_exists()autoloads the class, and PHP resolves parent classes at declaration time. A service class extending a class from an unavailable module throws anErrorthat kills the bootstrap before PHPStan analyzes a single file:Canvas hit this:
canvas_headlessregisters a decorator for acustom_elementsservice withdecoration_on_invalid: ignore, anddrupal/custom_elementssits inrequire-dev. Symfony ignores the decorator at runtime. phpstan-drupal fataled anyway, because the crash happens during class load, not container compilation. See https://git.drupalcode.org/project/canvas/-/merge_requests/1460, which works around it with an explicitclass:key.Fix
Catch
Throwablearound both shorthandclass_exists()calls (DrupalAutoloader,ServiceMap) and skip the service when its class cannot load.ServiceMap::setDrupalServices()also skips decorator registration when the decorating service was dropped — previously an undefined array key.Tests
service_map_brokenwith a shorthand service whose class extends a class from a missing module. Every bootstrap-dependent test now exercises the failure path; without the fix,DrupalContainerDynamicReturnTypeTestfatals with the exact error above.ServiceMapFactoryTest::testShorthandServiceWithUnloadableClasscoversServiceMapdirectly: the broken service is skipped and the decorated service survives with zero decorators.🤖 Generated with Claude Code