symfony/symfony · error · InvalidArgumentException
Invalid value provided for mode, use one of "%s::DISABLED" o
Error message
Invalid value provided for mode, use one of "%s::DISABLED" or "%s::ENABLED".
What it means
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.
Source
Thrown at src/Symfony/Bundle/WebProfilerBundle/EventListener/WebDebugToolbarListener.php:67
private bool $interceptRedirects = false,
private int $mode = self::ENABLED,
private ?UrlGeneratorInterface $urlGenerator = null,
private string $excludedAjaxPaths = '^/bundles|^/_wdt',
private ?ContentSecurityPolicyHandler $cspHandler = null,
private ?DumpDataCollector $dumpDataCollector = null,
private bool $ajaxReplace = false,
) {
}
public function isEnabled(): bool
{
return self::DISABLED !== $this->mode;
}
public function setMode(int $mode): void
{
if (self::DISABLED !== $mode && self::ENABLED !== $mode) {
throw new \InvalidArgumentException(\sprintf('Invalid value provided for mode, use one of "%s::DISABLED" or "%s::ENABLED".', self::class, self::class));
}
$this->mode = $mode;
}
public function onKernelResponse(ResponseEvent $event): void
{
$response = $event->getResponse();
$request = $event->getRequest();
if ($response->headers->has('X-Debug-Token') && null !== $this->urlGenerator) {
try {
$response->headers->set(
'X-Debug-Token-Link',
$this->urlGenerator->generate('_profiler', ['token' => $response->headers->get('X-Debug-Token')], UrlGeneratorInterface::ABSOLUTE_URL)
);
} catch (\Exception $e) {
$response->headers->set('X-Debug-Error', $e::class.': '.preg_replace('/\s+/', ' ', $e->getMessage()));View on GitHub (pinned to 698e28026c)
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.
Example fix
// before $listener->setMode(0); // after use Symfony\Bundle\WebProfilerBundle\EventListener\WebDebugToolbarListener; $listener->setMode(WebDebugToolbarListener::DISABLED);
Defensive patterns
Strategy: type-guard
Validate before calling
$mode = in_array($rawMode, [WebDebugToolbarListener::DISABLED, WebDebugToolbarListener::ENABLED], true)
? $rawMode
: WebDebugToolbarListener::DISABLED;
$listener->setMode($mode); Type guard
function isValidWdtMode(int $mode): bool {
return in_array($mode, [
WebDebugToolbarListener::DISABLED,
WebDebugToolbarListener::ENABLED,
], true);
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- The profiler template "%s.html.twig" for data collector "%s"
- The following keys are not valid for the importmap entry "%s
- The options tags, tag, parameters & parameter cannot be comb
- The options tags, tag, parameters & parameter cannot be comb
- Validation support cannot be enabled as the Validator compon
AI-assisted analysis of symfony/symfony@698e28026c (2026-08-06).
Data as JSON: /api/errors/fa008e3cb723776d.
Report an issue: GitHub.