{"record":{"id":"275596fac95e9b88","repo":"symfony/translation","slug":"unable-to-load-file-s-yamlfileloader","errorCode":null,"errorMessage":"Unable to load file \"%s\".","messagePattern":"Unable to load file \"(.+?)\"\\.","errorType":"exception","errorClass":"InvalidResourceException","httpStatus":null,"severity":"error","filePath":"Loader/YamlFileLoader.php","lineNumber":46,"sourceCode":"\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":28,"sourceCodeEnd":52,"githubUrl":"https://github.com/symfony/translation/blob/ae9e8a51bc29780d63c7f9efd6005d7c875e100b/Loader/YamlFileLoader.php#L28-L52","documentation":"Thrown by the YamlFileLoader (translation resource loader) as an InvalidResourceException when a YAML translation file parses to valid YAML but the top-level value is not an array (it is a non-null scalar, e.g. a string or number). Translation catalogues must be mappings of message keys to translations, so any other top-level shape cannot be loaded.","triggerScenarios":"Loading a translation resource (e.g. via Translatable / Translator->addResource or loadResource) where the YAML file parses successfully with Yaml::PARSE_CONSTANT but yields a non-null, non-array root node such as `foo` or `123` instead of a mapping.","commonSituations":"A translator edited a messages.yaml file and accidentally replaced the mapping with a single scalar line; an empty-ish file containing just a quoted string; a file that lost its structure after a bad merge; wrong file (e.g. a README or config YAML) registered as a translation resource.","solutions":["Open the YAML file and make its top level a mapping (key: value lines) instead of a scalar.","Check for accidental edits/merges that flattened the file structure.","Verify the file registered as a translation resource is actually a translation catalogue file.","Run `php -r \"var_dump((new Symfony\\Component\\Yaml\\Parser())->parseFile('messages.yaml', Yaml::PARSE_CONSTANT));\"` to confirm the parsed root is an array."],"exampleFix":"// before (messages.yaml)\ntranslations\n\n// after (messages.yaml)\nhello: Hello\nbye: Goodbye","handlingStrategy":"validation","validationCode":"$parsed = (new \\Symfony\\Component\\Yaml\\Parser())->parseFile($file, Yaml::PARSE_CONSTANT);\nif (null !== $parsed && !is_array($parsed)) {\n    throw new \\InvalidArgumentException(\"$file must be a YAML mapping of translations\");\n}","typeGuard":"if (!is_array($parsed)) { /* reject or coerce */ }","tryCatchPattern":"try {\n    $translator->addResource('yaml', $file, 'en');\n} catch (InvalidResourceException $e) {\n    // inspect $e->getMessage(); fix the YAML root node\n}","preventionTips":["Keep translation YAML files as top-level key: value mappings.","Lint translation files in CI with the YAML parser before deployment.","Never register non-translation YAML files as translator resources."],"tags":["yaml","translation","resource-loading","invalid-format"],"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"}