{"record":{"id":"816b5a9c2f93f85d","repo":"symfony/translation","slug":"cannot-load-resource-s","errorCode":null,"errorMessage":"Cannot load resource \"%s\".","messagePattern":"Cannot load resource \"(.+?)\"\\.","errorType":"exception","errorClass":"InvalidResourceException","httpStatus":null,"severity":"error","filePath":"Loader/IcuDatFileLoader.php","lineNumber":43,"sourceCode":"{\n    public function load(mixed $resource, string $locale, string $domain = 'messages'): MessageCatalogue\n    {\n        if (!stream_is_local($resource.'.dat')) {\n            throw new InvalidResourceException(\\sprintf('This is not a local file \"%s\".', $resource));\n        }\n\n        if (!file_exists($resource.'.dat')) {\n            throw new NotFoundResourceException(\\sprintf('File \"%s\" not found.', $resource));\n        }\n\n        try {\n            $rb = new \\ResourceBundle($locale, $resource);\n        } catch (\\Exception) {\n            $rb = null;\n        }\n\n        if (!$rb) {\n            throw new InvalidResourceException(\\sprintf('Cannot load resource \"%s\".', $resource));\n        } elseif (intl_is_failure($rb->getErrorCode())) {\n            throw new InvalidResourceException($rb->getErrorMessage(), $rb->getErrorCode());\n        }\n\n        $messages = $this->flatten($rb);\n        $catalogue = new MessageCatalogue($locale);\n        $catalogue->add($messages, $domain);\n\n        if (class_exists(FileResource::class)) {\n            $catalogue->addResource(new FileResource($resource.'.dat'));\n        }\n\n        return $catalogue;\n    }\n}\n","sourceCodeStart":25,"sourceCodeEnd":59,"githubUrl":"https://github.com/symfony/translation/blob/ae9e8a51bc29780d63c7f9efd6005d7c875e100b/Loader/IcuDatFileLoader.php#L25-L59","documentation":"IcuDatFileLoader::load() constructs a \\ResourceBundle($locale, $resource); if the bundle cannot be created (null/false returned, caught exception) it throws InvalidResourceException('Cannot load resource...'). The file exists but ResourceBundle could not parse or open it as a valid ICU bundle.","triggerScenarios":"ResourceBundle constructor returns falsy for an existing but invalid/empty/incompatible .dat bundle, or the bundle lacks the requested locale data and ResourceBundle reports it as missing.","commonSituations":"Corrupted or truncated .dat file, bundle compiled with an ICU version incompatible with the PHP intl extension, wrong bundle path passed so ResourceBundle finds nothing, or missing intl/icu data.","solutions":["Regenerate the .dat bundle with an ICU version matching your PHP intl extension's ICU.","Verify the bundle path is the base path ResourceBundle expects (bundles directory pattern).","Test the bundle directly: new \\ResourceBundle($locale, $path) and inspect getErrorCode().","Confirm the intl extension is installed and its ICU version (php --ri intl) is compatible with the bundle."],"exampleFix":"// before\n$rb = new \\ResourceBundle('en_FR', '/app/resources/messages'); // bundle has no en_FR\n// after\n$rb = new \\ResourceBundle('fr_FR', '/app/resources/messages');\nif (!$rb || intl_is_failure($rb->getErrorCode())) {\n    throw new \\RuntimeException('Invalid ICU bundle: '.$rb?->getErrorMessage());\n}","handlingStrategy":"try-catch","validationCode":"$rb = new \\ResourceBundle($locale, $basePath);\nif (!$rb || intl_is_failure($rb->getErrorCode())) {\n    throw new \\RuntimeException('Unusable ICU bundle: '.($rb?->getErrorMessage() ?? 'null bundle'));\n}","typeGuard":"function isValidResourceBundle(\\ResourceBundle $rb): bool { return intl_is_failure($rb->getErrorCode()) === false; }","tryCatchPattern":"try {\n    $catalogue = $loader->load($basePath, $locale);\n} catch (Symfony\\Component\\Translation\\Exception\\InvalidResourceException $e) {\n    error_log('ICU bundle invalid: '.$e->getMessage());\n    $catalogue = new MessageCatalogue($locale);\n}","preventionTips":["Compile bundles with an ICU version matching php-intl (check php --ri intl).","Validate bundles at build time with ResourceBundle directly.","Never hand-edit or truncate .dat files.","Test bundle loading in CI on the same intl version as production."],"tags":["icu","intl","resource-bundle","translation","corrupt-file"],"backgroundTag":"file-read-failed","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"}