symfony/routing · error · InvalidArgumentException

The routing file " " contains unsupported keys for " ": "…

Error message

The routing file "%s" contains unsupported keys for "%s": "%s". Expected one of: "%s".

What it means

validate() compares the definition's keys against the loader's AVAILABLE_KEYS allowlist and throws an InvalidArgumentException listing unsupported keys and the valid alternatives. This guards against typos and keys belonging to other loaders' schemas.

Solutions

  1. Replace each listed unsupported key with the correct AVAILABLE_KEYS key (fix typos like 'requirments' -> 'requirements').
  2. Remove keys that have no effect for this loader.
  3. Check the loader's supported key list / documentation for the exact schema.

Example fix

# before
home:
    path: /
    requirments:
        id: \d+
# after
home:
    path: /
    requirements:
        id: \d+
Defensive patterns

Strategy: validation

Validate before calling

$extra = array_diff(array_keys($config), self::AVAILABLE_KEYS);
if ($extra) { throw new \InvalidArgumentException('Unsupported keys: ' . implode(',', $extra)); }

Try / catch

try { $loader->load($file); } catch (\InvalidArgumentException $e) { /* rename/remove the unsupported keys listed */ }

Prevention

When it happens

Trigger: Using keys not in self::AVAILABLE_KEYS, e.g. misspelled 'requirments', or keys valid in other config formats like 'condition' where unsupported, in the routing file at $path for route $name.

Common situations: Typoed config keys in YAML; copy-pasting options from another loader/bundle that uses a different schema; stale keys left after upgrades when the allowlist changed.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of symfony/routing@83fa223250 (2026-09-14). Data as JSON: /api/errors/c3f0718ec74ac70b. Report an issue: GitHub.

Appendix: source

Thrown at Loader/ContentLoaderTrait.php:217

        }
    }

    /**
     * @throws \InvalidArgumentException If one of the provided config keys is not supported,
     *                                   something is missing or the combination is nonsense
     */
    private function validate(mixed $config, string $name, string $path): void
    {
        if (!\is_array($config)) {
            throw new \InvalidArgumentException(\sprintf('The definition of "%s" in "%s" must be an array.', $name, $path));
        }
        if (isset($config['alias'])) {
            $this->validateAlias($config, $name, $path);

            return;
        }
        if ($extraKeys = array_diff(array_keys($config), self::AVAILABLE_KEYS)) {
            throw new \InvalidArgumentException(\sprintf('The routing file "%s" contains unsupported keys for "%s": "%s". Expected one of: "%s".', $path, $name, implode('", "', $extraKeys), implode('", "', self::AVAILABLE_KEYS)));
        }
        if (isset($config['resource']) && isset($config['path'])) {
            throw new \InvalidArgumentException(\sprintf('The routing file "%s" must not specify both the "resource" key and the "path" key for "%s". Choose between an import and a route definition.', $path, $name));
        }
        if (!isset($config['resource']) && isset($config['type'])) {
            throw new \InvalidArgumentException(\sprintf('The "type" key for the route definition "%s" in "%s" is unsupported. It is only available for imports in combination with the "resource" key.', $name, $path));
        }
        if (!isset($config['resource']) && !isset($config['path'])) {
            throw new \InvalidArgumentException(\sprintf('You must define a "path" for the route "%s" in file "%s".', $name, $path));
        }
        if (isset($config['controller']) && isset($config['defaults']['_controller'])) {
            throw new \InvalidArgumentException(\sprintf('The routing file "%s" must not specify both the "controller" key and the defaults key "_controller" for "%s".', $path, $name));
        }
        if (isset($config['stateless']) && isset($config['defaults']['_stateless'])) {
            throw new \InvalidArgumentException(\sprintf('The routing file "%s" must not specify both the "stateless" key and the defaults key "_stateless" for "%s".', $path, $name));
        }
        if (isset($config['firewall']) && isset($config['defaults']['_firewall'])) {
            throw new \InvalidArgumentException(\sprintf('The routing file "%s" must not specify both the "firewall" key and the defaults key "_firewall" for "%s".', $path, $name));

View on GitHub (pinned to 83fa223250)