{"record":{"id":"5ffefd763fed33cd","repo":"cube-js/cube","slug":"service-not-found","errorCode":null,"errorMessage":"Service not found: {}","messagePattern":"Service not found: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"rust/cubesql/cubesql/src/config/injection.rs","lineNumber":119,"sourceCode":"        let pending = self\n            .init_guards\n            .read()\n            .await\n            .get(name)\n            .unwrap_or_else(|| panic!(\"Service is not found: {}\", name))\n            .clone();\n        // println!(\"Locking service: {}\", name);\n        // TODO cycle depends lead to dead lock here\n        let _l = pending.lock().await;\n\n        if let Some(s) = self.try_get_service(name).await {\n            return s;\n        }\n\n        let factories = self.factories.read().await;\n        let factory = factories\n            .get(name)\n            .unwrap_or_else(|| panic!(\"Service not found: {}\", name));\n        let service = factory(self.this.upgrade().unwrap()).await;\n        // println!(\"Setting service: {}\", name);\n        self.services\n            .write()\n            .await\n            .insert(name.to_string(), service.clone());\n        service.clone().downcast(service).unwrap()\n    }\n\n    pub async fn try_get_service<T: ?Sized + Send + Sync + 'static>(\n        &self,\n        name: &str,\n    ) -> Option<Arc<T>> {\n        self.services\n            .read()\n            .await\n            .get(name)\n            .map(|s| s.clone().downcast(s.clone()).unwrap())","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/cube-js/cube/blob/7d981676b36392fec34088b9afab6bdcad40207c/rust/cubesql/cubesql/src/config/injection.rs#L101-L137","documentation":"After the init-guard phase, get_service falls back to the factories map to construct a lazily-initialized service. If no factory is registered under the requested name, it panics 'Service not found'. Like error 556, it reflects missing DI registration.","triggerScenarios":"get_service called for a name present in init_guards but whose factory was never added to self.factories — e.g. a service initialized but never given a factory, or name mismatch between registration and lookup.","commonSituations":"Adding a service's init guard during refactoring but forgetting the factory closure; renaming service constants so registration and lookup keys diverge.","solutions":["Register the factory for the service name via the injector's add_factory/registration API","Make both registration and lookup use the same shared service-name constant","Trace which code path requests the service and align the startup wiring"],"exampleFix":"// before\ninjector.add_init_guard(ORDER_SERVICE, ...); // factory missing\n// after\ninjector.add_init_guard(ORDER_SERVICE, ...);\ninjector.add_factory(ORDER_SERVICE, |injector| async move { Ok(Arc::new(OrderService::new(injector))) });","handlingStrategy":"validation","validationCode":"// Boot-time self-check that every declared service has a factory\npub async fn verify_factories(injector: &Injector, names: &[&str]) {\n    for n in names {\n        if !injector.has_factory(n).await {\n            panic!(\"No factory registered for service '{}'\", n);\n        }\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pair add_init_guard/add_service with an add_factory for the same key","Use typed helper methods (get_service_typed) with constants to avoid name drift","Review DI wiring in code review whenever a new service is introduced"],"tags":["rust","panic","dependency-injection","service-registration"],"backgroundTag":"service-not-registered","analyzedSha":"7d981676b36392fec34088b9afab6bdcad40207c","analyzedAt":"2026-09-02T03:45:10.400Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}