{"record":{"id":"f026f97fd2d87bc1","repo":"symfony/translation","slug":"class-s-used-for-service-s-cannot-be-found","errorCode":null,"errorMessage":"Class \"%s\" used for service \"%s\" cannot be found.","messagePattern":"Class \"(.+?)\" used for service \"(.+?)\" cannot be found\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"DependencyInjection/LoggingTranslatorPass.php","lineNumber":40,"sourceCode":" */\nclass LoggingTranslatorPass implements CompilerPassInterface\n{\n    public function process(ContainerBuilder $container): void\n    {\n        if (!$container->hasAlias('logger') || !$container->hasAlias('translator')) {\n            return;\n        }\n\n        if (!$container->hasParameter('translator.logging') || !$container->getParameter('translator.logging')) {\n            return;\n        }\n\n        $translatorAlias = $container->getAlias('translator');\n        $definition = $container->getDefinition((string) $translatorAlias);\n        $class = $container->getParameterBag()->resolveValue($definition->getClass());\n\n        if (!$r = $container->getReflectionClass($class)) {\n            throw new InvalidArgumentException(\\sprintf('Class \"%s\" used for service \"%s\" cannot be found.', $class, $translatorAlias));\n        }\n\n        if (!$r->isSubclassOf(TranslatorInterface::class) || !$r->isSubclassOf(TranslatorBagInterface::class)) {\n            return;\n        }\n\n        $container->getDefinition('translator.logging')->setDecoratedService('translator');\n        $warmer = $container->getDefinition('translation.warmer');\n        $subscriberAttributes = $warmer->getTag('container.service_subscriber');\n        $warmer->clearTag('container.service_subscriber');\n\n        foreach ($subscriberAttributes as $k => $v) {\n            if ((!isset($v['id']) || 'translator' !== $v['id']) && (!isset($v['key']) || 'translator' !== $v['key'])) {\n                $warmer->addTag('container.service_subscriber', $v);\n            }\n        }\n        $warmer->addTag('container.service_subscriber', ['key' => 'translator', 'id' => 'translator.logging.inner']);\n    }","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/symfony/translation/blob/ae9e8a51bc29780d63c7f9efd6005d7c875e100b/DependencyInjection/LoggingTranslatorPass.php#L22-L58","documentation":"Thrown by LoggingTranslatorPass::process when the class resolved from the 'translator' service definition cannot be reflected, i.e. the class does not exist or cannot be autoloaded. The compiler pass needs to inspect the class to check it implements TranslatorInterface and TranslatorBagInterface before wiring the logging translator decorator.","triggerScenarios":"Running the Symfony container compile with a 'translator' alias/definition whose resolved class does not exist — typically when 'translator.class' parameter is wrong, a custom translator class name is mistyped, or the class file was removed/renamed without updating the service definition.","commonSituations":"Custom Translator class renamed without updating services.yaml; typo in class name in a service definition; compiling a container in a context where the translator class is not autoloadable; stale cached parameters defining an old class name.","solutions":["Verify the class name on the 'translator' service definition (or the class the 'translator' alias points to) exists and is autoloadable with `class_exists()`","Fix the class name or FQCN typo in the service definition / parameter","Clear and warm the Symfony cache (cache:clear) after renaming classes","If you intentionally have no translator, ensure the 'translator' alias and its definition are removed so the pass is skipped"],"exampleFix":"// before (services.yaml)\nApp\\Translator\\MyTraductor: ~\n// after\nApp\\Translator\\MyTranslator: ~","handlingStrategy":"validation","validationCode":"if (!class_exists($class = $container->getParameterBag()->resolveValue($definition->getClass()))) { throw new \\LogicException(\"Translator class {$class} does not exist\"); }","typeGuard":"function translatorClassExists(string $class): bool { return class_exists($class); }","tryCatchPattern":"try { $pass->process($container); } catch (InvalidArgumentException $e) { // translator class missing: fix service definition }","preventionTips":["Run `bin/console cache:clear` after renaming any custom Translator class","Keep custom translator class FQCNs in one config place and reference via parameters","Run container compilation in CI to catch missing classes early"],"tags":["symfony","dependency-injection","class-not-found"],"backgroundTag":"class-not-found","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"}