{"record":{"id":"d43f10a66c883718","repo":"symfony/translation","slug":"0-the-file-s-does-not-contain-valid-yaml","errorCode":"0","errorMessage":"The file \"%s\" does not contain valid YAML: ","messagePattern":"The file \"(.+?)\" does not contain valid YAML: ","errorType":"exception","errorClass":"InvalidResourceException","httpStatus":null,"severity":"error","filePath":"Loader/YamlFileLoader.php","lineNumber":42,"sourceCode":" */\nclass YamlFileLoader extends FileLoader\n{\n    private YamlParser $yamlParser;\n\n    protected function loadResource(string $resource): array\n    {\n        if (!isset($this->yamlParser)) {\n            if (!class_exists(YamlParser::class)) {\n                throw new LogicException('Loading translations from the YAML format requires the Symfony Yaml component.');\n            }\n\n            $this->yamlParser = new YamlParser();\n        }\n\n        try {\n            $messages = $this->yamlParser->parseFile($resource, Yaml::PARSE_CONSTANT);\n        } catch (ParseException $e) {\n            throw new InvalidResourceException(\\sprintf('The file \"%s\" does not contain valid YAML: ', $resource).$e->getMessage(), 0, $e);\n        }\n\n        if (null !== $messages && !\\is_array($messages)) {\n            throw new InvalidResourceException(\\sprintf('Unable to load file \"%s\".', $resource));\n        }\n\n        return $messages ?: [];\n    }\n}\n","sourceCodeStart":24,"sourceCodeEnd":52,"githubUrl":"https://github.com/symfony/translation/blob/ae9e8a51bc29780d63c7f9efd6005d7c875e100b/Loader/YamlFileLoader.php#L24-L52","documentation":"The YAML parser raised a ParseException while parsing the translation file; the loader wraps it in an InvalidResourceException with this prefix and appends the parser's message. Additionally, if the parsed document is a non-array scalar, the loader rejects it as unloadable.","triggerScenarios":"Calling YamlFileLoader::loadResource() (via load()) on a .yaml file with syntax errors — bad indentation, tabs, duplicate keys, unquoted special characters — or a file whose top level parses to a scalar instead of an array.","commonSituations":"Tabs used for indentation; missing space after a colon; multi-document files; editors mangling encoding; a translation file containing just a string/number at top level.","solutions":["Read the chained ParseException message for the exact line and fix the YAML syntax (indentation, colons, quotes).","Replace tab characters with spaces; YAML forbids tabs for indentation.","Ensure the top-level structure is a mapping of keys to messages (an array when parsed).","Validate the file with a YAML linter or yaml-lint before deploying."],"exampleFix":"// before\nmessages:\n\thello: Hello   # tab indentation\n// after\nmessages:\n    hello: Hello   # spaces","handlingStrategy":"try-catch","validationCode":"try {\n    \\Symfony\\Component\\Yaml\\Yaml::parseFile($resource);\n} catch (\\Symfony\\Component\\Yaml\\Exception\\ParseException $e) {\n    throw new \\RuntimeException('Bad YAML in '.$resource.': '.$e->getMessage());\n}","typeGuard":null,"tryCatchPattern":"try {\n    $catalogue = $loader->load($resource, $locale);\n} catch (InvalidResourceException $e) {\n    if (str_contains($e->getMessage(), 'does not contain valid YAML')) {\n        $this->logger->error('YAML translation parse failure', ['file' => $resource, 'detail' => $e->getPrevious()?->getMessage()]);\n    }\n    throw $e;\n}","preventionTips":["Use spaces, never tabs, for YAML indentation.","Lint all translation YAML files in CI (yaml-lint or symfony console lint:yaml).","Ensure top-level YAML is a mapping (key: value messages).","Watch for duplicate keys and unquoted special characters like @, %, and colons in values."],"tags":["php","yaml","parse-error"],"backgroundTag":"yaml-parse-error","analyzedSha":"ae9e8a51bc29780d63c7f9efd6005d7c875e100b","analyzedAt":"2026-09-15T22:29:15.305Z","contentChangedAt":"2026-09-15T22:29:15.305Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}