tonhowtf/omniget · error

Failed to add torrent

Error message

Failed to add torrent: {}

What it means

magnet.rs throws this when librqbit's add_torrent returns an Err, wrapping the underlying library error via anyhow::bail!("Failed to add torrent: {}"). It means the torrent could not be registered with the session at all — the source may be unreachable, invalid, or the session is in a bad state.

Solutions

  1. Read the wrapped inner error (e.to_string() after the prefix) to identify the real librqbit cause.
  2. Validate the magnet URI / torrent file before calling download (parse the magnet, check the .torrent file exists).
  3. Confirm the librqbit session is running and healthy (not stopped/shutdown) before adding torrents.
  4. For magnets, ensure DHT is enabled or valid trackers are present so the torrent can be constructed.
  5. If it appeared after a librqbit upgrade, check the add_torrent API/options changes.

Example fix

// before
let resp = session.add_torrent(add_torrent, Some(torrent_opts)).await?;
// after
let resp = session.add_torrent(add_torrent, Some(torrent_opts)).await
    .map_err(|e| anyhow::anyhow!("Failed to add torrent (magnet={}): {e:#}", opts.url))?;
// plus pre-validation:
// magnet::Url::parse(&opts.url)?;
Defensive patterns

Strategy: validation

Validate before calling

// validate source before adding
if url.starts_with("magnet:") {
    let m = magnet_url:: MagnetUrl::parse(url)?; // parse errors surface early
} else {
    tokio::fs::metadata(&url).await?; // .torrent file must exist
}

Try / catch

match session.add_torrent(src, opts).await {
    Err(e) => Err(anyhow!("Failed to add torrent: {e:#}")),
    Ok(r) => Ok(r),
}

Prevention

When it happens

Trigger: session.add_torrent(add_torrent, Some(torrent_opts)).await returns Err(e); magnet.rs:216 formats it into 'Failed to add torrent: {e}'. Typical underlying causes: invalid magnet URI/torrent file, unreadable torrent source, session shutdown.

Common situations: Malformed or unsupported magnet link pasted by the user; torrent file missing/unreadable on disk; DHT disabled and no trackers for the magnet; librqbit session crashed or was stopped before the add; incompatible info-hash/torrent data.

Related errors


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

Appendix: source

Thrown at src-tauri/omniget-core/src/platforms/magnet.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)