{"record":{"id":"93b91df1319afac0","repo":"symfony/http-kernel","slug":"controller-s-requires-the-s-argument-that-could-not-be","errorCode":null,"errorMessage":"Controller \"%s\" requires the \"$%s\" argument that could not be resolved. Possible reasons: %s","messagePattern":"Controller \"(.+?)\" requires the \"\\$(.+?)\" argument that could not be resolved\\. Possible reasons: (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"Controller/ArgumentResolver.php","lineNumber":137,"sourceCode":"                    // continue to the next controller argument\n                    continue 2;\n                }\n            }\n\n            $reasons = array_map(static fn (NearMissValueResolverException $e) => $e->getMessage(), $valueResolverExceptions);\n            if (!$reasons) {\n                $reasons[] = 'Either the argument is nullable and no null value has been provided, no default value has been provided or there is a non-optional argument after this one.';\n            }\n\n            $reasonCounter = 1;\n            if (\\count($reasons) > 1) {\n                foreach ($reasons as $i => $reason) {\n                    $reasons[$i] = $reasonCounter.') '.$reason;\n                    ++$reasonCounter;\n                }\n            }\n\n            throw new \\RuntimeException(\\sprintf('Controller \"%s\" requires the \"$%s\" argument that could not be resolved. '.($reasonCounter > 1 ? 'Possible reasons: ' : '').'%s', $metadata->getControllerName(), $metadata->getName(), implode(' ', $reasons)));\n        }\n\n        return $arguments;\n    }\n\n    /**\n     * @return iterable<int, ValueResolverInterface>\n     */\n    public static function getDefaultArgumentValueResolvers(): iterable\n    {\n        return [\n            new RequestAttributeValueResolver(),\n            new RequestValueResolver(),\n            new SessionValueResolver(),\n            new DefaultValueResolver(),\n            new VariadicValueResolver(),\n        ];\n    }","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/symfony/http-kernel/blob/aa3a39d7286a62cdfea98f0e69c651a3da6e36cf/Controller/ArgumentResolver.php#L119-L155","documentation":"ArgumentResolver::getArguments() throws RuntimeException when no value resolver could resolve a required controller argument. The message aggregates numbered 'possible reasons' collected from resolvers that came close (NearMissValueResolverException) to help diagnose why resolution failed.","triggerScenarios":"Invoking a controller whose argument has no default value, is not nullable, and for which no registered resolver yields a value — e.g. an untyped/scalar argument without #[MapRequestPayload]-style attributes, a service argument not autowired, or the required request attribute/query parameter absent.","commonSituations":"Forgetting #[MapRequestPayload]/#[CurrentUser] attributes on typed value objects; scalar controller arguments without defaults (works only in certain legacy configurations); calling the controller programmatically without providing the argument; route not passing a required {_format}/attribute; missing bundles that provided resolvers.","solutions":["Read the numbered 'possible reasons' in the message — they point at which resolvers almost matched and why they declined.","Annotate the argument with the appropriate attribute (#[(Map)QueryString/RequestPayload/File/User]) or give it a default/null-able type.","Ensure the argument type is class/enum-based and a matching resolver service is registered and tagged (argument.value_resolver).","If the value should come from the route, add it to the route requirements/defaults or fetch it from Request inside the controller."],"exampleFix":"// before\npublic function edit(Request $request, ProductDto $dto) {}\n// after\npublic function edit(#[MapRequestPayload] ProductDto $dto) {}","handlingStrategy":"try-catch","validationCode":"foreach ((new \\ReflectionMethod($controller, '__invoke'))->getParameters() as $p) {\n    if (!$p->getType() instanceof \\ReflectionNamedType && !$p->isDefaultValueAvailable() && !$p->allowsNull()) {\n        // ensure an attribute or resolver exists\n    }\n}","typeGuard":null,"tryCatchPattern":"try { $response = $controller(...$args); } catch (\\RuntimeException $e) { if (str_contains($e->getMessage(), 'could not be resolved')) { /* add attribute/default or provide the argument */ } throw $e; }","preventionTips":["Annotate DTO/value-object arguments with the matching #[Map*] attribute","Read the numbered 'possible reasons' — they name the failing resolvers","Keep resolver services tagged argument.value_resolver and registered in the current env","Avoid untyped or scalar arguments without defaults in controllers"],"tags":["symfony","controller","argument-resolver","unresolvable-argument"],"backgroundTag":"missing-required-argument","analyzedSha":"aa3a39d7286a62cdfea98f0e69c651a3da6e36cf","analyzedAt":"2026-09-13T18:03:36.509Z","contentChangedAt":"2026-09-13T18:03:36.509Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}