symfony/http-kernel · error · LogicException

Nested expressions in validation groups are not supported…

Error message

Nested expressions in validation groups are not supported. Use a single Expression or a list of strings (or a GroupSequence) instead.

What it means

When validationGroups resolves to an array, each element must be a plain string group (or the top-level value may be a GroupSequence). If any array element is itself an Expression object, Symfony throws this LogicException because nested expressions are unsupported inside group arrays.

Solutions

  1. Use a single top-level Expression instead of nesting it in an array
  2. Return only strings from the closure/expression
  3. Use a GroupSequence at the top level for sequential group evaluation

Example fix

// before
validationGroups: [new Expression("'Default'")]
// after
validationGroups: "'Default'"
Defensive patterns

Strategy: validation

Validate before calling

foreach ($groups as $g) { if ($g instanceof Expression) { throw new \InvalidArgumentException('no nested expressions'); } }

Type guard

!($group instanceof \Symfony\Component\Validator\Constraints\Expression)

Try / catch

try { $response = $kernel->handle($request); } catch (\LogicException $e) { if (str_contains($e->getMessage(), 'Nested expressions')) { /* flatten expression */ } throw $e; }

Prevention

When it happens

Trigger: Returning [new Expression('...')] or mixing an Expression into an array of validation groups in a #[MapRequestPayload(validationGroups: ...)] attribute.

Common situations: Developers attempt per-element dynamic groups by embedding Expressions in arrays instead of using a single expression or a closure returning strings.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of symfony/http-kernel@aa3a39d728 (2026-09-13). Data as JSON: /api/errors/35570180722b3fcf. Report an issue: GitHub.

Appendix: source

Thrown at Controller/ArgumentResolver/RequestPayloadValueResolver.php:345

    }

    private function resolveValidationGroups(Expression|string|GroupSequence|\Closure|array|null $validationGroups, ControllerArgumentsEvent $event): string|GroupSequence|array|null
    {
        if ($validationGroups instanceof Expression || $validationGroups instanceof \Closure) {
            $validationGroups = $event->evaluate($validationGroups, $this->expressionLanguage);
        }

        if (null === $validationGroups || \is_string($validationGroups) || $validationGroups instanceof GroupSequence) {
            return $validationGroups;
        }

        if (!\is_array($validationGroups)) {
            throw new \LogicException('The validation groups expression or closure must return a string, an array of strings, or a GroupSequence.');
        }

        foreach ($validationGroups as $group) {
            if ($group instanceof Expression) {
                throw new \LogicException('Nested expressions in validation groups are not supported. Use a single Expression or a list of strings (or a GroupSequence) instead.');
            }

            if ($group instanceof \Closure) {
                throw new \LogicException('Nested closures in validation groups are not supported. Use a single Closure or a list of strings (or a GroupSequence) instead.');
            }

            if ($group instanceof GroupSequence) {
                throw new \LogicException('GroupSequence cannot be used inside an array of validation groups. Pass the GroupSequence as the top-level validationGroups value instead.');
            }

            if (!\is_string($group)) {
                throw new \LogicException('Validation groups must be strings.');
            }
        }

        return $validationGroups;
    }

View on GitHub (pinned to aa3a39d728)