tonhowtf/omniget · error · anyhow::Error

api client init failed

Error message

api client init failed: {}

What it means

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.

Solutions

  1. Inspect the i18n key in the message for the concrete init failure reason.
  2. Clear or repair the app's stored Bilibili cookie/account state and retry.
  3. Check system TLS certificates and proxy environment variables that may break HTTP client setup.
  4. Verify network stack availability (DNS/TLS) since client construction may probe connectivity.
Defensive patterns

Strategy: try-catch

Try / catch

let client = match build_api_client(slug, user_agent) {
    Ok(c) => c,
    Err(e) => {
        eprintln!("cannot start download: {e:#}");
        return Err(e);
    }
};

Prevention

When it happens

Trigger: `api::ApiClient::new()` returns Err — typically when it cannot initialize its HTTP client or load required cookie/state for anonymous or account access.

Common situations: 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.

Related errors


AI-assisted analysis of tonhowtf/omniget@8600b91f42 (2026-09-12). Data as JSON: /api/errors/17cc43ecfa542812. Report an issue: GitHub.

Appendix: source

Thrown at src-tauri/src/platforms/bilibili/mod.rs:204

    Ok(DownloadResult {
        file_path: result.final_path,
        file_size_bytes: result.bytes,
        duration_seconds: parsed
            .items
            .first()
            .and_then(|i| i.duration_seconds)
            .unwrap_or(0.0),
        torrent_id: None,
    })
}

fn build_api_client(
    slug: Option<&str>,
    user_agent: Option<&str>,
) -> anyhow::Result<api::ApiClient> {
    let mut client =
        api::ApiClient::new().map_err(|e| anyhow!("api client init failed: {}", e.i18n_key()))?;
    if let Some(ua) = user_agent.filter(|s| !s.is_empty()) {
        client = client.with_user_agent(ua);
    }
    match slug {
        Some(s) => client = client.with_account(s),
        None => client = client.with_anonymous_cookies(),
    }
    Ok(client)
}

fn sanitize(s: &str) -> String {
    let cleaned = sanitize_filename::sanitize(s);
    if cleaned.is_empty() {
        "video".to_string()
    } else {
        cleaned
    }
}

View on GitHub (pinned to 8600b91f42)