{"record":{"id":"83c52e7983136628","repo":"tonhowtf/omniget","slug":"failed-to-add-torrent","errorCode":null,"errorMessage":"Failed to add torrent: {}","messagePattern":"Failed to add torrent: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/platforms/magnet.rs","lineNumber":216,"sourceCode":"        };\n        let torrent_opts = AddTorrentOptions {\n            overwrite: true,\n            only_files,\n            trackers,\n            ..Default::default()\n        };\n\n        tracing::info!(\"[magnet] adding torrent, output: {}\", output_dir.display());\n        let (torrent_id, managed_torrent) =\n            match session.add_torrent(add_torrent, Some(torrent_opts)).await {\n                Ok(resp) => match resp {\n                    librqbit::AddTorrentResponse::Added(id, handle) => (id, handle),\n                    librqbit::AddTorrentResponse::AlreadyManaged(id, handle) => (id, handle),\n                    librqbit::AddTorrentResponse::ListOnly(_) => {\n                        anyhow::bail!(\"Torrent was added in list-only mode\");\n                    }\n                },\n                Err(e) => anyhow::bail!(\"Failed to add torrent: {}\", e),\n            };\n\n        tracing::info!(\n            \"[magnet] torrent added (id={}), waiting for download...\",\n            torrent_id\n        );\n\n        if let Some(slot) = &opts.torrent_id_slot {\n            *slot.lock().await = Some(torrent_id);\n        }\n\n        let completion = managed_torrent.wait_until_completed();\n        tokio::pin!(completion);\n\n        let cancel_rx = opts.cancel_token.clone();\n        let session_for_cancel = session.clone();\n\n        loop {","sourceCodeStart":198,"sourceCodeEnd":234,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/platforms/magnet.rs#L198-L234","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Read the wrapped inner error (e.to_string() after the prefix) to identify the real librqbit cause.","Validate the magnet URI / torrent file before calling download (parse the magnet, check the .torrent file exists).","Confirm the librqbit session is running and healthy (not stopped/shutdown) before adding torrents.","For magnets, ensure DHT is enabled or valid trackers are present so the torrent can be constructed.","If it appeared after a librqbit upgrade, check the add_torrent API/options changes."],"exampleFix":"// before\nlet resp = session.add_torrent(add_torrent, Some(torrent_opts)).await?;\n// after\nlet resp = session.add_torrent(add_torrent, Some(torrent_opts)).await\n    .map_err(|e| anyhow::anyhow!(\"Failed to add torrent (magnet={}): {e:#}\", opts.url))?;\n// plus pre-validation:\n// magnet::Url::parse(&opts.url)?;","handlingStrategy":"validation","validationCode":"// validate source before adding\nif url.starts_with(\"magnet:\") {\n    let m = magnet_url:: MagnetUrl::parse(url)?; // parse errors surface early\n} else {\n    tokio::fs::metadata(&url).await?; // .torrent file must exist\n}","typeGuard":null,"tryCatchPattern":"match session.add_torrent(src, opts).await {\n    Err(e) => Err(anyhow!(\"Failed to add torrent: {e:#}\")),\n    Ok(r) => Ok(r),\n}","preventionTips":["Validate magnet URIs and .torrent file paths before download","Ensure the librqbit session is running before add_torrent","Keep DHT enabled or supply trackers for magnet-only sources"],"tags":["torrent","librqbit","magnet","add-torrent"],"backgroundTag":"api-error-response","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"}