{"record":{"id":"e805ac4563e0f00b","repo":"tonhowtf/omniget","slug":"failed-to-add-torrent-mod","errorCode":null,"errorMessage":"Failed to add torrent: {}","messagePattern":"Failed to add torrent: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-tauri/src/platforms/magnet/mod.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/src/platforms/magnet/mod.rs#L198-L234","documentation":"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.","triggerScenarios":"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).","commonSituations":"Corrupted or truncated magnet link copied from a browser; torrent file deleted between listing and download; incompatible librqbit version where option fields changed.","solutions":["Read the wrapped inner error `e` in the message to identify the root cause","Validate the magnet URI / .torrent path before calling download()","Confirm the output_dir exists and is writable","Check librqbit version compatibility if options were recently changed"],"exampleFix":"// before\nlet code = \"magnet:?xt=urn:btih:\" + user_input;\ndownloader.download(...).await?;\n// after\nlet code = format!(\"magnet:?xt=urn:btih:{}\", user_input);\nanyhow::ensure!(code.len() > 40, \"magnet info-hash missing\");\ndownloader.download(...).await.context(\"adding torrent\")?;","handlingStrategy":"try-catch","validationCode":"anyhow::ensure!(magnet.starts_with(\"magnet:?xt=urn:btih:\"), \"invalid magnet URI\");\nanyhow::ensure!(std::path::Path::new(output_dir).is_dir(), \"output_dir missing\");","typeGuard":"fn is_valid_magnet(u: &str) -> bool {\n    u.starts_with(\"magnet:?xt=urn:btih:\") && u.len() > 40\n}","tryCatchPattern":"match downloader.download(...).await {\n    Err(e) if format!(\"{e:#}\").contains(\"Failed to add torrent\") => {\n        error!(\"torrent rejected: {e:#}\");\n    }\n    other => other?,\n}","preventionTips":["Validate magnet URIs before download","Ensure output_dir exists and is writable","Pin/verify librqbit version when upgrading option structs"],"tags":["torrent","librqbit","api-error"],"backgroundTag":"api-request-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"}