{"record":{"id":"e9de95c0a73a4a0a","repo":"symfony/routing","slug":"the-file-s-does-not-contain-valid-yaml","errorCode":null,"errorMessage":"The file \"%s\" does not contain valid YAML: ","messagePattern":"The file \"(.+?)\" does not contain valid YAML: ","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"Loader/YamlFileLoader.php","lineNumber":57,"sourceCode":"     */\n    public function load(mixed $file, ?string $type = null): RouteCollection\n    {\n        $path = $this->locator->locate($file);\n\n        if (!stream_is_local($path)) {\n            throw new \\InvalidArgumentException(\\sprintf('This is not a local file \"%s\".', $path));\n        }\n\n        if (!file_exists($path)) {\n            throw new \\InvalidArgumentException(\\sprintf('File \"%s\" not found.', $path));\n        }\n\n        $this->yamlParser ??= new YamlParser();\n\n        try {\n            $parsedConfig = $this->yamlParser->parseFile($path, Yaml::PARSE_CONSTANT);\n        } catch (ParseException $e) {\n            throw new \\InvalidArgumentException(\\sprintf('The file \"%s\" does not contain valid YAML: ', $path).$e->getMessage(), 0, $e);\n        }\n\n        $collection = new RouteCollection();\n        $collection->addResource(new FileResource($path));\n\n        // empty file\n        if (null === $parsedConfig) {\n            return $collection;\n        }\n\n        // not an array\n        if (!\\is_array($parsedConfig)) {\n            throw new \\InvalidArgumentException(\\sprintf('The file \"%s\" must contain a YAML array.', $path));\n        }\n\n        $this->loadContent($collection, $parsedConfig, $path, $file);\n\n        return $collection;","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/symfony/routing/blob/83fa223250b50f4f018c011e101c330e65ac63cc/Loader/YamlFileLoader.php#L39-L75","documentation":"YamlFileLoader::load() wraps the YAML parse in a try/catch and rethrows an InvalidArgumentException when symfony/yaml's ParseException occurs, prefixing the file path. The original parse error (bad indentation, invalid syntax, bad encoding) is preserved as the previous exception and appended in the message.","triggerScenarios":"A routes.yaml with YAML syntax errors: wrong indentation, tabs instead of spaces, unescaped special characters, duplicate keys in strict mode, invalid UTF-8, or malformed flow syntax like [controller: action].","commonSituations":"Editing routes.yaml by hand; copying examples with mixed indentation; CI parsing files produced by templating tools that inject invalid YAML; Symfony 5.3+ deprecation-triggering syntax or old short array controller syntax like [AppBundle:Blog:list] not parseable.","solutions":["Read the appended ParseException message for the exact line/column and fix the YAML indentation/syntax there","Validate the file: php -r \"(new Symfony\\Component\\Yaml\\Parser())->parseFile('routes.yaml');\" or run a YAML linter","Replace tabs with spaces (YAML forbids tabs)","Convert legacy short controller syntax to the current [Controller::class, 'method'] form"],"exampleFix":"// routes.yaml before (invalid: tab indentation)\nindex:\n\t path: /\n\t controller: App\\Controller\\HomeController::index\n// after\nindex:\n    path: /\n    controller: App\\Controller\\HomeController::index","handlingStrategy":"try-catch","validationCode":"try { (new \\Symfony\\Component\\Yaml\\Parser())->parseFile($path); } catch (\\Symfony\\Component\\Yaml\\Exception\\ParseException $e) { echo $e->getMessage(); }","typeGuard":"null","tryCatchPattern":"try { $loader->load($file); } catch (\\InvalidArgumentException $e) { if (str_contains($e->getMessage(), 'valid YAML')) { log($e->getPrevious()?->getMessage()); } throw $e; }","preventionTips":["Lint YAML files in CI (yamllint or a parse check)","Use spaces, never tabs, in YAML","Inspect $e->getPrevious()->getMessage() for the exact line/column"],"tags":["routing","yaml","parse-error","symfony"],"backgroundTag":"yaml-parse-error","analyzedSha":"83fa223250b50f4f018c011e101c330e65ac63cc","analyzedAt":"2026-09-14T03:19:46.280Z","contentChangedAt":"2026-09-14T03:19:46.280Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}