Skip to content

Conversation

@yoeunes
Copy link
Contributor

@yoeunes yoeunes commented Nov 8, 2025

Q A
Branch? 6.4
Bug fix? yes
New feature? no
Deprecations? no
Issues -
License MIT

This PR fixes a bug where MissingOptionsException error messages for nested prototypes generated an incomplete path. When an option was missing inside a prototype that was itself nested inside another prototype, the key of the parent prototype was omitted from the error message.

The fix ensures the parent's prototype index is correctly tracked and prepended when resolving nested options, providing a full and accurate path for easier debugging.

Example:

Given the following nested prototype setup:

$resolver->setOptions('connections', static function (OptionsResolver $connResolver) {
    $connResolver->setPrototype(true); // Parent prototype
    // ...
    $connResolver->setOptions('replicas', static function (OptionsResolver $replicaResolver) {
        $replicaResolver->setPrototype(true); // Nested prototype
        $replicaResolver->setRequired(['host']);
    });
});

And this configuration, which is missing a host in main_db's second replica:

$options = [
    'connections' => [
        'main_db' => [
            // ...
            'replicas' => [
                ['host' => 'replica-01.local'],
                [], // Missing 'host' here
            ],
        ],
    ],
];
$resolver->resolve($options);

Before (The Bug):
The exception message was incorrect, missing the main_db key:
The required option "connections[replicas][1][host]" is missing.

After (The Fix):
The exception message is now correct and includes the full path:
The required option "connections[main_db][replicas][1][host]" is missing.

A test case (testNestedPrototypeErrorPathHasFullContext) has been added to cover this scenario and prevent regressions.

@nicolas-grekas nicolas-grekas force-pushed the options-resolver-nested-prototype-path-6.4 branch from a7fda15 to 7d9c810 Compare November 12, 2025 13:07
@nicolas-grekas
Copy link
Member

Thank you @yoeunes.

@nicolas-grekas nicolas-grekas merged commit 19f6580 into symfony:6.4 Nov 12, 2025
9 of 11 checks passed
This was referenced Nov 13, 2025
This was referenced Dec 7, 2025
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.

4 participants