Skip to content

[4.x] Report a mapped command with a missing service in ContainerLoader::get() - #36

Open
Hackwar wants to merge 1 commit into
joomla-framework:4.x-devfrom
Hackwar:4.x-container-loader-missing-service
Open

Hackwar wants to merge 1 commit into
joomla-framework:4.x-devfrom
Hackwar:4.x-container-loader-missing-service

Conversation

@Hackwar

@Hackwar Hackwar commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Summary of Changes

ContainerLoader::get() threw Command "x" does not exist. both for a name that is not in the command map and for a mapped name whose service the container does not have. The second case is a container misconfiguration, and the message sent people looking for a typo in the command name.

get() now checks the two conditions separately: a name missing from the map still throws CommandNotFoundException with the same message; a mapped name whose service is not registered throws Symfony\Component\Console\Exception\LogicException: Command "x" is mapped to the service "y", which is not registered in the container.

has() is unchanged (it still requires both the map entry and the service), so Application::hasCommand()/getCommand() behave as before; the new exception surfaces when the loader is called directly.

Behaviour change: code that calls ContainerLoader::get() directly and catches CommandNotFoundException for a mapped-but-unregistered service now gets a LogicException instead.

Testing Instructions

tests/Loader/ContainerLoaderTest.php:

  • testTheLoaderDoesNotRetrieveAnUnknownCommand now uses a name that is not in the map and checks the message;
  • testTheLoaderReportsAMappedCommandWhoseServiceIsMissing fails on 4.x-dev (it gets the CommandNotFoundException) and passes with this change;
  • testTheLoaderDoesNotHaveAMappedCommandWhoseServiceIsMissing pins the unchanged has() behaviour.

Documentation Changes Required

docs/overview.md: the "Things to know" paragraph about ContainerLoader now describes both cases.

🤖 Generated with Claude Code

get() threw "Command "x" does not exist." both for a name that is not
in the command map and for a mapped name whose service the container
does not have. The second case is a container misconfiguration, so it
now throws a LogicException naming the missing service ID.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Hackwar

Hackwar commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

Approved, but the documentation is rather confusing.

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.

1 participant