{"record":{"id":"e9177c62920ff314","repo":"tonhowtf/omniget","slug":"download-cancelled-e9177c","errorCode":null,"errorMessage":"Download cancelled","messagePattern":"Download cancelled","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"info","filePath":"src-tauri/src/platforms/reddit/mod.rs","lineNumber":218,"sourceCode":"            }\n        }\n        variants\n    }\n\n    async fn download_video_with_fallback(\n        &self,\n        video_url: &str,\n        output: &std::path::Path,\n        progress_tx: mpsc::Sender<ProgressUpdate>,\n        cancel: Option<&tokio_util::sync::CancellationToken>,\n    ) -> anyhow::Result<u64> {\n        let variants = Self::get_resolution_variants(video_url);\n        let mut last_err = anyhow!(\"No resolution available\");\n\n        for variant in &variants {\n            if let Some(token) = cancel {\n                if token.is_cancelled() {\n                    return Err(anyhow!(\"Download cancelled\"));\n                }\n            }\n            match direct_downloader::download_direct(\n                &self.client,\n                variant,\n                output,\n                progress_tx.clone(),\n                cancel,\n            )\n            .await\n            {\n                Ok(bytes) => return Ok(bytes),\n                Err(e) => {\n                    last_err = e;\n                    let _ = tokio::fs::remove_file(output).await;\n                }\n            }\n        }","sourceCodeStart":200,"sourceCodeEnd":236,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/src/platforms/reddit/mod.rs#L200-L236","documentation":"Before each variant download attempt the loop checks the caller-supplied CancellationToken; if cancellation was requested it aborts the whole fallback loop with 'Download cancelled'. This is an intentional cooperative-cancellation error, not a malfunction.","triggerScenarios":"The user pressed cancel in the UI (or the app dropped the download task) while download_video_with_fallback was iterating resolution variants; the token passed via native_download's cancel Option is triggered between attempts.","commonSituations":"User cancels a slow Reddit video download; app shutdown cancels in-flight downloads; UI clears a download queue and cancels each token.","solutions":["Catch this error and treat it as a normal, expected outcome (no retry, no error toast).","Check the cancellation token before starting the download at all to avoid starting work that will be aborted.","Remove the partial output file after a cancelled download.","Distinguish cancellation from real failures in progress reporting (emit a 'cancelled' state, not 'failed')."],"exampleFix":"// before\nmatch native_download(url, opts, progress_tx.clone(), Some(&token)).await {\n    Err(e) => report_error(e),\n    Ok(n) => report_done(n),\n}\n// after\nmatch native_download(url, opts, progress_tx.clone(), Some(&token)).await {\n    Err(e) if e.to_string().contains(\"Download cancelled\") || token.is_cancelled() => report_cancelled(),\n    Err(e) => report_error(e),\n    Ok(n) => report_done(n),\n}","handlingStrategy":"try-catch","validationCode":"// check before starting at all\nif token.is_cancelled() { return Ok(()); }","typeGuard":null,"tryCatchPattern":"match download(url, out, Some(&token)).await {\n    Err(e) if token.is_cancelled() || e.to_string().contains(\"cancelled\") => {\n        let _ = tokio::fs::remove_file(out).await; // clean partial output\n        report_cancelled();\n    }\n    Err(e) => report_error(e),\n    Ok(n) => report_done(n),\n}","preventionTips":["Treat cancellation as an expected state, not a failure","Check the token before spawning the download task","Delete partial output files after cancellation","Use the CancellationToken itself to classify the error rather than string matching"],"tags":["reddit","cancellation","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"}