{"record":{"id":"fa008e3cb723776d","repo":"symfony/symfony","slug":"invalid-value-provided-for-mode-use-one-of-s-d","errorCode":null,"errorMessage":"Invalid value provided for mode, use one of \"%s::DISABLED\" or \"%s::ENABLED\".","messagePattern":"Invalid value provided for mode, use one of \"(.+?)::DISABLED\" or \"(.+?)::ENABLED\"\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Symfony/Bundle/WebProfilerBundle/EventListener/WebDebugToolbarListener.php","lineNumber":67,"sourceCode":"        private bool $interceptRedirects = false,\n        private int $mode = self::ENABLED,\n        private ?UrlGeneratorInterface $urlGenerator = null,\n        private string $excludedAjaxPaths = '^/bundles|^/_wdt',\n        private ?ContentSecurityPolicyHandler $cspHandler = null,\n        private ?DumpDataCollector $dumpDataCollector = null,\n        private bool $ajaxReplace = false,\n    ) {\n    }\n\n    public function isEnabled(): bool\n    {\n        return self::DISABLED !== $this->mode;\n    }\n\n    public function setMode(int $mode): void\n    {\n        if (self::DISABLED !== $mode && self::ENABLED !== $mode) {\n            throw new \\InvalidArgumentException(\\sprintf('Invalid value provided for mode, use one of \"%s::DISABLED\" or \"%s::ENABLED\".', self::class, self::class));\n        }\n\n        $this->mode = $mode;\n    }\n\n    public function onKernelResponse(ResponseEvent $event): void\n    {\n        $response = $event->getResponse();\n        $request = $event->getRequest();\n\n        if ($response->headers->has('X-Debug-Token') && null !== $this->urlGenerator) {\n            try {\n                $response->headers->set(\n                    'X-Debug-Token-Link',\n                    $this->urlGenerator->generate('_profiler', ['token' => $response->headers->get('X-Debug-Token')], UrlGeneratorInterface::ABSOLUTE_URL)\n                );\n            } catch (\\Exception $e) {\n                $response->headers->set('X-Debug-Error', $e::class.': '.preg_replace('/\\s+/', ' ', $e->getMessage()));","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/symfony/symfony/blob/698e28026c22cf35d032cdb6e800db48b1535790/src/Symfony/Bundle/WebProfilerBundle/EventListener/WebDebugToolbarListener.php#L49-L85","documentation":"WebDebugToolbarListener::setMode() only accepts the class constants DISABLED (1) or ENABLED (2). Any other int (including 0, true coerced to 1 is fine, false coerced to 0 is NOT, booleans are not allowed) raises InvalidArgumentException. The message echoes the FQCN so the constants are referenced as WebDebugToolbarListener::DISABLED / ::ENABLED.","triggerScenarios":"Calling $wdtListener->setMode($x) with a value other than 1 or 2; passing a boolean (PHP coerces but false => 0 fails the check); wiring a parameter that resolved to an int other than 1/2 in services.yaml; programmatic mode toggling in tests or a compiler pass.","commonSituations":"Developer sets framework.profiler.toolbar_mode (custom) to 0 thinking 0 means off; passing true/false from env vars; a stale bundle version where constants differed; misconfiguring web_profiler.web_debug_toolbar.mode.","solutions":["Pass WebDebugToolbarListener::ENABLED or ::DISABLED explicitly rather than raw literals.","If disabling from config, set web_profiler.web_debug_toolbar.mode: 2 (ENABLED) or omit and use the interceptor toggle, or set intercept_redirects and toolbar via the bundle's intended config keys.","Guard boolean inputs with a cast to the correct constant: $x ? ENABLED : DISABLED."],"exampleFix":"// before\n$listener->setMode(0);\n\n// after\nuse Symfony\\Bundle\\WebProfilerBundle\\EventListener\\WebDebugToolbarListener;\n$listener->setMode(WebDebugToolbarListener::DISABLED);","handlingStrategy":"type-guard","validationCode":"$mode = in_array($rawMode, [WebDebugToolbarListener::DISABLED, WebDebugToolbarListener::ENABLED], true)\n    ? $rawMode\n    : WebDebugToolbarListener::DISABLED;\n$listener->setMode($mode);","typeGuard":"function isValidWdtMode(int $mode): bool {\n    return in_array($mode, [\n        WebDebugToolbarListener::DISABLED,\n        WebDebugToolbarListener::ENABLED,\n    ], true);\n}","tryCatchPattern":null,"preventionTips":["Always pass the class constants, never literals or booleans.","When reading mode from config, validate it in an Extension/Configuration with an enum constraint.","Add a unit test asserting setMode() accepts only the two constants."],"tags":["web-profiler","config","symfony","validation"],"analyzedSha":"698e28026c22cf35d032cdb6e800db48b1535790","analyzedAt":"2026-08-06T23:40:49.025Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}