Commit 19f6580
committed
bug #62344 [OptionsResolver] Fix missing prototype key in nested error paths (yoeunes)
This PR was merged into the 6.4 branch.
Discussion
----------
[OptionsResolver] Fix missing prototype key in nested error paths
| 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:
```php
$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:
```php
$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.
Commits
-------
7d9c810 [OptionsResolver] Fix missing prototype key in nested error pathsFile tree
2 files changed
+47
-0
lines changed- src/Symfony/Component/OptionsResolver
- Tests
2 files changed
+47
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
964 | 964 | | |
965 | 965 | | |
966 | 966 | | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
967 | 972 | | |
968 | 973 | | |
969 | 974 | | |
| |||
Lines changed: 42 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2595 | 2595 | | |
2596 | 2596 | | |
2597 | 2597 | | |
| 2598 | + | |
| 2599 | + | |
| 2600 | + | |
| 2601 | + | |
| 2602 | + | |
| 2603 | + | |
| 2604 | + | |
| 2605 | + | |
| 2606 | + | |
| 2607 | + | |
| 2608 | + | |
| 2609 | + | |
| 2610 | + | |
| 2611 | + | |
| 2612 | + | |
| 2613 | + | |
| 2614 | + | |
| 2615 | + | |
| 2616 | + | |
| 2617 | + | |
| 2618 | + | |
| 2619 | + | |
| 2620 | + | |
| 2621 | + | |
| 2622 | + | |
| 2623 | + | |
| 2624 | + | |
| 2625 | + | |
| 2626 | + | |
| 2627 | + | |
| 2628 | + | |
| 2629 | + | |
| 2630 | + | |
| 2631 | + | |
| 2632 | + | |
| 2633 | + | |
| 2634 | + | |
| 2635 | + | |
| 2636 | + | |
| 2637 | + | |
| 2638 | + | |
| 2639 | + | |
2598 | 2640 | | |
0 commit comments