{"record":{"id":"5fcaa5efa27cf3f9","repo":"symfony/translation","slug":"rb-geterrormessage-icuresfileloader","errorCode":null,"errorMessage":"$rb->getErrorMessage()","messagePattern":"\\$rb->getErrorMessage\\(\\)","errorType":"exception","errorClass":"InvalidResourceException","httpStatus":null,"severity":"error","filePath":"Loader/IcuResFileLoader.php","lineNumber":45,"sourceCode":"    {\n        if (!stream_is_local($resource)) {\n            throw new InvalidResourceException(\\sprintf('This is not a local file \"%s\".', $resource));\n        }\n\n        if (!is_dir($resource)) {\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(DirectoryResource::class)) {\n            $catalogue->addResource(new DirectoryResource($resource));\n        }\n\n        return $catalogue;\n    }\n\n    /**\n     * Flattens an ResourceBundle.\n     *\n     * The scheme used is:\n     *   key { key2 { key3 { \"value\" } } }","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/symfony/translation/blob/ae9e8a51bc29780d63c7f9efd6005d7c875e100b/Loader/IcuResFileLoader.php#L27-L63","documentation":"When the ResourceBundle loads but ICU reports a failure code (intl_is_failure), the loader wraps ICU's own error message and code in InvalidResourceException. This means the bundle exists but ICU rejected it — e.g. a format/version mismatch between the .res file and the ICU library.","triggerScenarios":"load() on a .res file whose internal ICU error code (UErrorCode) indicates failure — truncated or wrongly-versioned bundle data, mismatched ICU version that produced the file. Raised in testDatEnglishLoad/testDatFrenchLoad flows.","commonSituations":".res files generated with a newer ICU than the runtime intl extension; partially uploaded/truncated resource files; bundles referencing fallback locales missing from the data.","solutions":["Read the exception's ICU error code and look it up in ICU's UErrorCode documentation to identify the exact failure.","Regenerate .res bundles with genrb from a matching (or older) ICU toolchain.","Upgrade the PHP intl extension / ICU library to a version compatible with the bundle files.","Re-download or re-deploy the resource files if they are truncated or corrupted."],"exampleFix":"// before\ncat = $loader->load('messages.res', 'fr'); // ICU failure code\n// after\n$rb = new \\ResourceBundle('fr', 'messages.res');\nif (intl_is_failure($rb->getErrorCode())) {\n    throw new \\RuntimeException('ICU error '.$rb->getErrorCode().': rebuild bundles with matching ICU');\n}","handlingStrategy":"try-catch","validationCode":"$rb = new \\ResourceBundle($locale, $resource);\nif (!$rb || intl_is_failure($rb->getErrorCode())) {\n    throw new \\RuntimeException('ICU error '.$rb->getErrorCode().': '.$rb->getErrorMessage());\n}","typeGuard":"function icuBundleLoads(string $locale, string $resource): bool {\n    $rb = @new \\ResourceBundle($locale, $resource);\n    return $rb !== null && !intl_is_failure($rb->getErrorCode());\n}","tryCatchPattern":"try {\n    $catalogue = $loader->load($resource, $locale);\n} catch (InvalidResourceException $e) {\n    error_log('ICU failure: '.$e->getMessage().' code '.$e->getCode());\n    $catalogue = $fallbackLoader->load($fallbackResource, $locale);\n}","preventionTips":["Regenerate bundles with a genrb version matching the runtime ICU","Record the ICU version used to build bundles in your build metadata","Add a smoke test that loads every locale bundle in CI","Handle IntlException/ICU codes explicitly rather than ignoring them"],"tags":["intl","icu","resource-bundle","translation"],"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"}