{"record":{"id":"36a93cdf537f125f","repo":"cube-js/cube","slug":"service-is-not-found","errorCode":null,"errorMessage":"Service is not found: {}","messagePattern":"Service is not found: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"rust/cubesql/cubesql/src/config/injection.rs","lineNumber":106,"sourceCode":"        self.init_guards\n            .write()\n            .await\n            .insert(name.to_string(), Arc::new(Mutex::new(())));\n    }\n}\n\nimpl Injector {\n    pub async fn get_service<T: ?Sized + Send + Sync + 'static>(&self, name: &str) -> Arc<T> {\n        if let Some(s) = self.try_get_service(name).await {\n            return s;\n        }\n\n        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","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/cube-js/cube/blob/7d981676b36392fec34088b9afab6bdcad40207c/rust/cubesql/cubesql/src/config/injection.rs#L88-L124","documentation":"CubeSQL uses a service injection container. get_service looks up an init guard for the named service before initialization; if the service name was never registered (no init guard exists), it panics 'Service is not found'. This indicates a DI wiring/registration bug rather than a runtime condition.","triggerScenarios":"get_service/get_service_typed called with a service name that was never added to the injector's init_guards; accessing a service before inject() registered it, or a typo'd service name in configuration wiring.","commonSituations":"Custom CubeSQL builds where a new service was used without registering its factory; refactors that renamed a service key but missed one lookup site; cyclic dependency comments nearby hint at ordering issues.","solutions":["Ensure the service factory is registered (inject/factory map) before any get_service call for that name","Verify the service name string matches the registered key exactly","Check startup ordering — registration must happen before dependent services resolve"],"exampleFix":"// before\nlet meta: Arc<MetaService> = injector.get_service_typed(META_SERVICE).await;\n// after\ninjector.add_factory(META_SERVICE, move |injector| { ... });\nlet meta: Arc<MetaService> = injector.get_service_typed(META_SERVICE).await;","handlingStrategy":"validation","validationCode":"// Verify a service is registered before resolving it\npub async fn assert_registered(injector: &Injector, name: &str) {\n    if !injector.has_service_or_guard(name).await {\n        panic!(\"Bug: service '{}' must be registered before use\", name);\n    }\n}","typeGuard":null,"tryCatchPattern":"// Panic is intentional for wiring bugs; fix at startup rather than catching.\n// Optionally validate all required services at boot:\nfor name in REQUIRED_SERVICES {\n    injector.get_service_typed::<dyn Any>(name).await\n        .unwrap_or_else(|e| panic!(\"startup DI check failed for {}: {:?}\", name, e));\n}","preventionTips":["Register every service factory during injector setup, before any resolution","Reference services through shared name constants, never raw strings","Add a startup smoke test that resolves all required services"],"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"}