{"record":{"id":"17cc43ecfa542812","repo":"tonhowtf/omniget","slug":"api-client-init-failed-mod","errorCode":null,"errorMessage":"api client init failed: {}","messagePattern":"api client init failed: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src-tauri/src/platforms/bilibili/mod.rs","lineNumber":204,"sourceCode":"\n    Ok(DownloadResult {\n        file_path: result.final_path,\n        file_size_bytes: result.bytes,\n        duration_seconds: parsed\n            .items\n            .first()\n            .and_then(|i| i.duration_seconds)\n            .unwrap_or(0.0),\n        torrent_id: None,\n    })\n}\n\nfn build_api_client(\n    slug: Option<&str>,\n    user_agent: Option<&str>,\n) -> anyhow::Result<api::ApiClient> {\n    let mut client =\n        api::ApiClient::new().map_err(|e| anyhow!(\"api client init failed: {}\", e.i18n_key()))?;\n    if let Some(ua) = user_agent.filter(|s| !s.is_empty()) {\n        client = client.with_user_agent(ua);\n    }\n    match slug {\n        Some(s) => client = client.with_account(s),\n        None => client = client.with_anonymous_cookies(),\n    }\n    Ok(client)\n}\n\nfn sanitize(s: &str) -> String {\n    let cleaned = sanitize_filename::sanitize(s);\n    if cleaned.is_empty() {\n        \"video\".to_string()\n    } else {\n        cleaned\n    }\n}","sourceCodeStart":186,"sourceCodeEnd":222,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/src/platforms/bilibili/mod.rs#L186-L222","documentation":"In `build_api_client` (src-tauri/src/platforms/bilibili/mod.rs:204), constructing the Bilibili `api::ApiClient` failed and the error is re-wrapped as \"api client init failed: {}\" with the original i18n key. This happens before any download starts, so the request never reaches Bilibili.","triggerScenarios":"`api::ApiClient::new()` returns Err — typically when it cannot initialize its HTTP client or load required cookie/state for anonymous or account access.","commonSituations":"Corrupt or unreadable local cookie/state storage; TLS or proxy misconfiguration on the machine preventing reqwest client construction; missing runtime dependencies for the HTTP stack.","solutions":["Inspect the i18n key in the message for the concrete init failure reason.","Clear or repair the app's stored Bilibili cookie/account state and retry.","Check system TLS certificates and proxy environment variables that may break HTTP client setup.","Verify network stack availability (DNS/TLS) since client construction may probe connectivity."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"let client = match build_api_client(slug, user_agent) {\n    Ok(c) => c,\n    Err(e) => {\n        eprintln!(\"cannot start download: {e:#}\");\n        return Err(e);\n    }\n};","preventionTips":["Verify app data directories are writable so client state can be created.","Keep TLS/proxy configuration valid on the host system.","Fail fast with a health check that constructs the client at startup rather than mid-download."],"tags":["rust","bilibili","api-client","initialization"],"backgroundTag":"module-init-failed","analyzedSha":"8600b91f4246848bac346874daa9e61c1fc5677a","analyzedAt":"2026-09-12T14:29:19.317Z","contentChangedAt":"2026-09-12T14:29:19.317Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}