{"record":{"id":"9bfe0f622e892cf5","repo":"tonhowtf/omniget","slug":"download-cancelled-magnet","errorCode":null,"errorMessage":"Download cancelled","messagePattern":"Download cancelled","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"info","filePath":"src-tauri/omniget-core/src/platforms/magnet.rs","lineNumber":266,"sourceCode":"                            \"[magnet] progress: {:.1}% ({:.1} MB / {:.1} MB)\",\n                            pct,\n                            downloaded as f64 / 1_048_576.0,\n                            total as f64 / 1_048_576.0,\n                        );\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()","sourceCodeStart":248,"sourceCodeEnd":284,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/platforms/magnet.rs#L248-L284","documentation":"magnet.rs throws this in the download wait loop when the cancel token fires while the torrent is downloading. The select branch logs 'download cancelled', attempts to delete the torrent from the session (best-effort, failure only logged), and then bails with 'Download cancelled'. It is expected cancellation, not a torrent error.","triggerScenarios":"In the tokio::select! over progress/completion/cancel, `_ = cancel_rx.cancelled()` triggers at magnet.rs:266; the torrent (torrent_id) is deleted via session_for_cancel.delete(TorrentIdOrHash::Id(...), false) before bailing.","commonSituations":"User cancels a slow torrent download; app shutdown; the download manager cancels and re-queues a torrent; stalled torrent causes a supervisor to cancel the attempt.","solutions":["Handle this message as normal user cancellation — stop and return silently rather than surfacing an error.","If cancellation was unintended, trace who fired cancel_rx (UI, timeout, shutdown) for this download id.","Verify the follow-up session.delete on cancel succeeded (a warn log 'failed to delete torrent on cancel' means cleanup leaked).","Prefer a typed cancellation signal over string-matching the error message in calling code."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"Err(e) if e.to_string() == \"Download cancelled\" => {\n    // normal path: torrent already deleted by the library; return quietly\n    Ok(DownloadOutcome::Cancelled)\n}","preventionTips":["Use per-download tokens scoped to one attempt only","Confirm the 'failed to delete torrent on cancel' warn is absent so state doesn't leak","Surface cancellation as a status, not an error, in the UI"],"tags":["cancel","torrent","magnet","download"],"backgroundTag":"operation-cancelled","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"}