symfony/routing · error · InvalidArgumentException

The routing file " " must not specify other keys than…

Error message

The routing file "%s" must not specify other keys than "alias" and "deprecated" for "%s".

What it means

When a routing entry defines an 'alias', the whole entry may only contain the 'alias' and 'deprecated' keys — aliases are pure redirects to another route name and carry no path, controller, etc. ContentLoaderTrait::validateAlias() throws InvalidArgumentException for any other key found in the entry.

Solutions

  1. Delete every key except 'alias' (and optionally 'deprecated') from the entry
  2. If the entry needs path/controller, it is not an alias — remove the 'alias' key and define a normal route
  3. Create a separate entry if you need both the original route and an alias

Example fix

# before
app_new:
    alias: app_old
    path: /old
    controller: App\Controller\OldController

# after
app_new:
    alias: app_old
Defensive patterns

Strategy: validation

Validate before calling

if (isset($config['alias'])) {
    $extra = array_diff(array_keys($config), ['alias', 'deprecated']);
    if ($extra) { throw new \LogicException(sprintf('Alias may only have alias/deprecated keys, got: %s', implode(',', $extra))); }
}

Type guard

function isPureAlias(array $config): bool { return isset($config['alias']) && empty(array_diff(array_keys($config), ['alias', 'deprecated'])); }

Try / catch

try { $collection = $loader->load($file, 'yaml'); } catch (\InvalidArgumentException $e) { /* alias entry has extra keys; strip them */ }

Prevention

When it happens

Trigger: A routing entry with an 'alias' key that also contains keys like 'path', 'controller', 'defaults' or 'requirements'.

Common situations: Converting an existing route into an alias (e.g. for a rename/deprecation) without deleting its old keys; copy-pasting a full route block and swapping 'path' for 'alias'.

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/d17dd8c8f94b85c2. Report an issue: GitHub.

Appendix: source

Thrown at Loader/ContentLoaderTrait.php:249

        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));
        }
    }

    /**
     * Validates that an alias definition only carries the `alias` and `deprecated` keys.
     *
     * @throws \InvalidArgumentException If one of the provided config keys is not supported,
     *                                   something is missing or the combination is nonsense
     */
    private function validateAlias(array $config, string $name, string $path): void
    {
        foreach ($config as $key => $value) {
            if (!\in_array($key, ['alias', 'deprecated'], true)) {
                throw new \InvalidArgumentException(\sprintf('The routing file "%s" must not specify other keys than "alias" and "deprecated" for "%s".', $path, $name));
            }

            if ('deprecated' === $key) {
                if (!isset($value['package'])) {
                    throw new \InvalidArgumentException(\sprintf('The routing file "%s" must specify the attribute "package" of the "deprecated" option for "%s".', $path, $name));
                }

                if (!isset($value['version'])) {
                    throw new \InvalidArgumentException(\sprintf('The routing file "%s" must specify the attribute "version" of the "deprecated" option for "%s".', $path, $name));
                }
            }
        }
    }
}

View on GitHub (pinned to 83fa223250)