symfony/routing · error · InvalidArgumentException

File " " not found.

Error message

File "%s" not found.

What it means

YamlFileLoader::load() throws this InvalidArgumentException when the located routing file does not exist on disk. Note the locator usually runs first and throws FileLocatorFileNotFoundException for unresolvable paths; this check catches cases where the located path vanished or stream_is_local passed but file_exists fails.

Solutions

  1. Verify the file exists at the exact path: ls -la <path> (mind case sensitivity)
  2. Fix the path in the router config / import statement
  3. If the file is optional, guard with file_exists() or is_file() before loading
  4. Ensure deployment includes the routes file in the artifact

Example fix

// before
$router = new Router($loader, 'config/route.yml');
// after
$router = new Router($loader, 'config/routes.yaml');
Defensive patterns

Strategy: validation

Validate before calling

if (!is_file($path)) { throw new \RuntimeException("Routing file missing: $path"); }

Type guard

null

Try / catch

try { $collection = $loader->load($file); } catch (\InvalidArgumentException $e) { if (str_contains($e->getMessage(), 'not found')) { /* use default routes */ } throw $e; }

Prevention

When it happens

Trigger: Passing a wrong or misspelled path to Router/YamlFileLoader::load(), referencing a file deleted at runtime, or an import in routes.yaml pointing to a nonexistent file with a resolvable-but-missing resolution.

Common situations: Typos in config/packages/routes paths; cache rebuilds after a file was removed; missing file in deployment artifact; case-sensitivity mismatch on Linux (Routes.yaml vs routes.yaml).

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


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

Appendix: source

Thrown at Loader/YamlFileLoader.php:49

        parseRoute as doParseRoute;
        validate as doValidate;
    }

    private YamlParser $yamlParser;

    /**
     * @throws \InvalidArgumentException When a route can't be parsed because YAML is invalid
     */
    public function load(mixed $file, ?string $type = null): RouteCollection
    {
        $path = $this->locator->locate($file);

        if (!stream_is_local($path)) {
            throw new \InvalidArgumentException(\sprintf('This is not a local file "%s".', $path));
        }

        if (!file_exists($path)) {
            throw new \InvalidArgumentException(\sprintf('File "%s" not found.', $path));
        }

        $this->yamlParser ??= new YamlParser();

        try {
            $parsedConfig = $this->yamlParser->parseFile($path, Yaml::PARSE_CONSTANT);
        } catch (ParseException $e) {
            throw new \InvalidArgumentException(\sprintf('The file "%s" does not contain valid YAML: ', $path).$e->getMessage(), 0, $e);
        }

        $collection = new RouteCollection();
        $collection->addResource(new FileResource($path));

        // empty file
        if (null === $parsedConfig) {
            return $collection;
        }

View on GitHub (pinned to 83fa223250)