{"record":{"id":"b1d854c0f03a8cca","repo":"symfony/translation","slug":"unable-to-load-file-s","errorCode":null,"errorMessage":"Unable to load file \"%s\".","messagePattern":"Unable to load file \"(.+?)\"\\.","errorType":"exception","errorClass":"InvalidResourceException","httpStatus":null,"severity":"error","filePath":"Loader/FileLoader.php","lineNumber":41,"sourceCode":"{\n    public function load(mixed $resource, string $locale, string $domain = 'messages'): MessageCatalogue\n    {\n        if (!stream_is_local($resource)) {\n            throw new InvalidResourceException(\\sprintf('This is not a local file \"%s\".', $resource));\n        }\n\n        if (!file_exists($resource)) {\n            throw new NotFoundResourceException(\\sprintf('File \"%s\" not found.', $resource));\n        }\n\n        $messages = $this->loadResource($resource);\n\n        // empty resource\n        $messages ??= [];\n\n        // not an array\n        if (!\\is_array($messages)) {\n            throw new InvalidResourceException(\\sprintf('Unable to load file \"%s\".', $resource));\n        }\n\n        $catalogue = parent::load($messages, $locale, $domain);\n\n        if (class_exists(FileResource::class)) {\n            $catalogue->addResource(new FileResource($resource));\n        }\n\n        return $catalogue;\n    }\n\n    /**\n     * @throws InvalidResourceException if stream content has an invalid format\n     */\n    abstract protected function loadResource(string $resource): array;\n}\n","sourceCodeStart":23,"sourceCodeEnd":58,"githubUrl":"https://github.com/symfony/translation/blob/ae9e8a51bc29780d63c7f9efd6005d7c875e100b/Loader/FileLoader.php#L23-L58","documentation":"FileLoader::load() calls the subclass's loadResource() and requires the result to be an array; if loadResource() returns a non-array it throws InvalidResourceException('Unable to load file...'). This indicates the concrete loader produced malformed output for the resource.","triggerScenarios":"A concrete loader's loadResource() returns null, false, an object, or otherwise non-array data for the given file, then FileLoader::load() detects !is_array($messages) and throws.","commonSituations":"Custom loader subclass whose loadResource() returns null on parse failure; corrupted/unreadable file parsed into a non-array; PHP version behavior change where a parser returns null on empty content.","solutions":["Fix the loadResource() implementation in the concrete loader so it always returns an array (coerce null/false to []).","Inspect the resource file for corruption or an unsupported format that makes the parser bail.","If using a custom loader, unit-test loadResource() against empty and malformed files.","Catch InvalidResourceException around load() to degrade to an empty catalogue."],"exampleFix":"// before\nprotected function loadResource(string $resource): array\n{\n    return yaml_parse_file($resource); // null on failure\n}\n// after\nprotected function loadResource(string $resource): array\n{\n    return yaml_parse_file($resource) ?? [];\n}","handlingStrategy":"try-catch","validationCode":"// For custom loaders: ensure loadResource() always returns array\n$result = $this->parse($resource);\nif (!is_array($result)) { $result = []; }","typeGuard":"function isStringKeyedArray(mixed $v): bool { return is_array($v); }","tryCatchPattern":"try {\n    $catalogue = $loader->load($path, $locale);\n} catch (Symfony\\Component\\Translation\\Exception\\InvalidResourceException $e) {\n    // fall back to empty catalogue and alert\n    error_log('Translation load failed: '.$e->getMessage());\n    $catalogue = new MessageCatalogue($locale);\n}","preventionTips":["Return [] instead of null from custom loadResource() on parse failure.","Unit-test custom loaders against empty and malformed files.","Keep the parser and PHP/intl versions consistent across environments.","Validate the file format before adding it to the translation resources."],"tags":["file-loader","translation","invalid-resource","custom-loader"],"backgroundTag":"type-mismatch","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"}