{"record":{"id":"dc66ae243d64cd5c","repo":"libnyanpasu/clash-nyanpasu","slug":"legacy-verge-bridge-is-not-managed","errorCode":null,"errorMessage":"legacy verge bridge is not managed","messagePattern":"legacy verge bridge is not managed","errorType":"exception","errorClass":"ClientError","httpStatus":null,"severity":"error","filePath":"backend/tauri/src/bridge/verge.rs","lineNumber":356,"sourceCode":"\n    fn legacy_mutation_partial(error: anyhow::Error, source: Option<ClientError>) -> ClientError {\n        let message = format!(\n            \"legacy mutation may have non-reversible side effects and requires reconciliation: {error:#}\"\n        );\n        if let Some(ClientError::PartialCommit(partial)) = source {\n            return partial.with_legacy_state_uncertain(message).into();\n        }\n\n        let primary = ClientError::Anyhow(error);\n        PartialCommit::new(&primary, Vec::new(), Vec::new(), Vec::new())\n            .with_legacy_state_uncertain(message)\n            .into()\n    }\n\n    fn managed(&self) -> ClientResult<&LegacyVergeBridgeInner> {\n        self.managed\n            .as_deref()\n            .ok_or_else(|| anyhow::anyhow!(\"legacy verge bridge is not managed\").into())\n    }\n\n    async fn get_verge_config_unlocked(&self) -> ClientResult<IVerge> {\n        let managed = self.managed()?;\n        let app = managed.client.get_app_config().await?;\n        let session = managed.client.get_session_state().await?;\n        let clash = managed.client.get_clash_config().await?;\n\n        Ok(super::legacy_iverge_from_typed(\n            self.legacy_store.snapshot()?,\n            &app,\n            &session,\n            &clash,\n        )?)\n    }\n\n    async fn refresh_legacy_projection(&self) -> ClientResult<IVerge> {\n        let managed = self.managed()?;","sourceCodeStart":338,"sourceCodeEnd":374,"githubUrl":"https://github.com/libnyanpasu/clash-nyanpasu/blob/f7dbce2997c633e484f54788035e770b3ee99773/backend/tauri/src/bridge/verge.rs#L338-L374","documentation":"Raised by `LegacyVergeBridge::managed()` when the bridge's optional `managed` field (`Option<...>`) is `None`, i.e. the bridge was constructed without being attached to a managed legacy verge store/client. Any operation that needs the managed inner (snapshot, get/patch verge config, run mutations) will fail with this error.","triggerScenarios":"Invoking any bridge operation (`patch_verge_config`, `get_verge_config`, `run_legacy_verge_mutation`, `replace_verge_config`) on a `LegacyVergeBridge` that was built without calling the setup that populates `self.managed` (e.g. used before bootstrap/`AppSupervisor` wired it, or in a context where the legacy bridge was intentionally disabled).","commonSituations":"Calling Tauri commands during app startup before the composition root has initialized the bridge; unit tests instantiating the bridge without a managed inner; a refactor making `managed` optional without guarding all call sites.","solutions":["Ensure the app bootstrap/composition root constructs and attaches the managed inner before any command uses the bridge.","Check initialization order: complete actor spawn and bridge setup before registering/serving Tauri commands.","In tests, construct the bridge with a managed inner (test fixtures with injected fake clients) instead of the bare constructor.","Add an early readiness check so commands return a clear 'not initialized' state rather than hitting this error."],"exampleFix":"// before: bridge used before setup\nlet bridge = LegacyVergeBridge::new();\nbridge.get_verge_config().await?; // panics-free error: not managed\n\n// after: setup first, then use\nlet bridge = LegacyVergeBridge::new();\nbridge.attach_managed(client, legacy_verge_path).await?; // populate managed\nbridge.get_verge_config().await?;","handlingStrategy":"type-guard","validationCode":"// guard before using the bridge\nif !bridge.is_managed() {\n    return Err(ClientError::from(anyhow::anyhow!(\n        \"verge bridge not initialized; complete bootstrap first\"\n    )));\n}","typeGuard":"fn is_managed(bridge: &LegacyVergeBridge) -> bool {\n    bridge.managed_handle().is_some()\n}","tryCatchPattern":"match bridge.get_verge_config().await {\n    Err(e) if e.to_string().contains(\"not managed\") => {\n        // bootstrap not finished; retry after initialization signal\n        bootstrap_ready.notified().await;\n    }\n    other => other?,\n}","preventionTips":["Wire the bridge in the composition root before registering Tauri commands.","Expose an explicit initialized/ready flag on the client facade.","In tests, always construct the bridge with a managed inner fixture.","Avoid making the managed dependency Optional in new code; inject it at construction."],"tags":["rust","initialization","dependency-injection","lifecycle"],"backgroundTag":"missing-required-config","analyzedSha":"f7dbce2997c633e484f54788035e770b3ee99773","analyzedAt":"2026-09-08T01:24:59.197Z","contentChangedAt":"2026-09-08T01:24:59.197Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}