{"record":{"id":"992205a0ee16e79c","repo":"tonhowtf/omniget","slug":"torrent-download-failed","errorCode":null,"errorMessage":"Torrent download failed: {}","messagePattern":"Torrent download failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/platforms/magnet.rs","lineNumber":270,"sourceCode":"                        );\n                        // Fallback: detect completion from stats when\n                        // wait_until_completed() doesn't resolve\n                        if downloaded >= total {\n                            tracing::info!(\"[magnet] download complete from stats (id={})\", torrent_id);\n                            break;\n                        }\n                    }\n                }\n                _ = cancel_rx.cancelled() => {\n                    tracing::info!(\"[magnet] download cancelled, removing torrent id={}\", torrent_id);\n                    if let Err(e) = session_for_cancel.delete(TorrentIdOrHash::Id(torrent_id), false).await {\n                        tracing::warn!(\"[magnet] failed to delete torrent on cancel: {}\", e);\n                    }\n                    anyhow::bail!(\"Download cancelled\");\n                }\n                res = &mut completion => {\n                    if let Err(e) = res {\n                        anyhow::bail!(\"Torrent download failed: {}\", e);\n                    }\n                    let _ = progress.send(ProgressUpdate::percent(100.0)).await;\n                    tracing::info!(\"[magnet] download complete (id={})\", torrent_id);\n                    break;\n                }\n            }\n        }\n\n        let (total_size, torrent_name) = managed_torrent\n            .with_metadata(|meta| {\n                let size = meta\n                    .info\n                    .iter_file_lengths()\n                    .ok()\n                    .map(|iter| iter.sum::<u64>())\n                    .unwrap_or_else(|| meta.file_infos.iter().map(|f| f.len).sum());\n                let name = meta\n                    .info","sourceCodeStart":252,"sourceCodeEnd":288,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/platforms/magnet.rs#L252-L288","documentation":"magnet.rs throws this when the torrent completion future itself returns Err — i.e. librqbit's own download failed — and download() re-raises it as 'Torrent download failed: {}'. The wrapped inner error from the torrent handle carries the actual cause (no peers, tracker failure, disk error, etc.).","triggerScenarios":"In the select loop, `res = &mut completion` yields Err(e) and magnet.rs:270 bails with the message plus the inner error. Happens whenever the torrent's downloading future terminates unsuccessfully before reaching 100%.","commonSituations":"Torrent with no seeders/peers; all trackers unreachable or DHT disabled; insufficient disk space for the payload; permission errors writing to output_dir; metadata never received for a magnet with no peers.","solutions":["Inspect the wrapped inner error (text after the prefix) to identify the root cause.","Check swarm health: seeders/peer count and tracker status for this torrent before retrying.","Verify output_dir is writable and has enough free space for the full payload.","For magnets, add working trackers or enable DHT so metadata/peers can be found.","Implement a bounded retry with backoff for transient peer/tracker failures."],"exampleFix":"// before\nmatch downloader.download(opts, progress).await {\n    Err(e) => show_error(e),\n    ...\n}\n// after\nmatch downloader.download(opts, progress).await {\n    Err(e) if e.to_string().starts_with(\"Torrent download failed:\") => {\n        let cause = e.to_string();\n        if swarm_has_no_peers(&cause) {\n            schedule_retry_with_backoff(opts); // transient\n        } else {\n            show_error(e); // disk/io/config issue\n        }\n    }\n    ...\n}","handlingStrategy":"retry","validationCode":"// pre-flight checks\nassert_dir_writable_and_has_space(&opts.output_dir, expected_size)?;","typeGuard":null,"tryCatchPattern":"Err(e) if e.to_string().starts_with(\"Torrent download failed:\") => {\n    if is_transient(&e) { retry_with_backoff(3) } else { propagate(e) }\n}","preventionTips":["Check seeder/peer availability before starting long torrents","Reserve disk space and verify output_dir permissions up front","Add healthy trackers and keep DHT enabled","Cap retries with exponential backoff for transient swarm errors"],"tags":["torrent","magnet","network","download"],"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"}