tonhowtf/omniget · error

Failed to add torrent

Error message

Failed to add torrent: {}

What it means

session.add_torrent returned an Err, so the torrent could not be registered with the librqbit session at all. The raw librqbit error is wrapped into this anyhow error with context. Causes include malformed magnet URIs, unreadable .torrent files, or invalid options.

Solutions

  1. Read the wrapped inner error `e` in the message to identify the root cause
  2. Validate the magnet URI / .torrent path before calling download()
  3. Confirm the output_dir exists and is writable
  4. Check librqbit version compatibility if options were recently changed

Example fix

// before
let code = "magnet:?xt=urn:btih:" + user_input;
downloader.download(...).await?;
// after
let code = format!("magnet:?xt=urn:btih:{}", user_input);
anyhow::ensure!(code.len() > 40, "magnet info-hash missing");
downloader.download(...).await.context("adding torrent")?;
Defensive patterns

Strategy: try-catch

Validate before calling

anyhow::ensure!(magnet.starts_with("magnet:?xt=urn:btih:"), "invalid magnet URI");
anyhow::ensure!(std::path::Path::new(output_dir).is_dir(), "output_dir missing");

Type guard

fn is_valid_magnet(u: &str) -> bool {
    u.starts_with("magnet:?xt=urn:btih:") && u.len() > 40
}

Try / catch

match downloader.download(...).await {
    Err(e) if format!("{e:#}").contains("Failed to add torrent") => {
        error!("torrent rejected: {e:#}");
    }
    other => other?,
}

Prevention

When it happens

Trigger: Adding a magnet URI that fails to parse, a .torrent file path that cannot be read/parsed, or options the session rejects (e.g. bad folder configuration).

Common situations: Corrupted or truncated magnet link copied from a browser; torrent file deleted between listing and download; incompatible librqbit version where option fields changed.

Understand the failure class

Background: "API request failed": what wrapped HTTP errors from external APIs mean and how to find the real cause — this error's family across 29 libraries.

Related errors


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

Appendix: source

Thrown at src-tauri/src/platforms/magnet/mod.rs:216

        };
        let torrent_opts = AddTorrentOptions {
            overwrite: true,
            only_files,
            trackers,
            ..Default::default()
        };

        tracing::info!("[magnet] adding torrent, output: {}", output_dir.display());
        let (torrent_id, managed_torrent) =
            match session.add_torrent(add_torrent, Some(torrent_opts)).await {
                Ok(resp) => match resp {
                    librqbit::AddTorrentResponse::Added(id, handle) => (id, handle),
                    librqbit::AddTorrentResponse::AlreadyManaged(id, handle) => (id, handle),
                    librqbit::AddTorrentResponse::ListOnly(_) => {
                        anyhow::bail!("Torrent was added in list-only mode");
                    }
                },
                Err(e) => anyhow::bail!("Failed to add torrent: {}", e),
            };

        tracing::info!(
            "[magnet] torrent added (id={}), waiting for download...",
            torrent_id
        );

        if let Some(slot) = &opts.torrent_id_slot {
            *slot.lock().await = Some(torrent_id);
        }

        let completion = managed_torrent.wait_until_completed();
        tokio::pin!(completion);

        let cancel_rx = opts.cancel_token.clone();
        let session_for_cancel = session.clone();

        loop {

View on GitHub (pinned to 8600b91f42)