tonhowtf/omniget · info

Download cancelled

Error message

Download cancelled

What it means

Thrown when the download's cancel_token is signalled while the receiver is still streaming bytes to disk. The partial output file is removed first, then this error aborts the download loop. It is the library's cooperative-cancellation mechanism, not an unexpected failure.

Solutions

  1. Treat this error as an intentional user abort: filter/match on the message or use a dedicated cancellation error variant and skip generic error reporting
  2. Don't retry automatically — the token was cancelled deliberately; re-arm a fresh cancel_token if a retry is desired
  3. Ensure the output_path directory is writable so the partial-file cleanup succeeds

Example fix

// before
if let Err(e) = p2p::download(&info, &opts, tx).await {
    ui.show_error(e.to_string());
}
// after
if let Err(e) = p2p::download(&info, &opts, tx).await {
    if e.to_string().contains("Download cancelled") {
        ui.show_info("Transfer cancelled by user");
    } else {
        ui.show_error(e.to_string());
    }
}
Defensive patterns

Strategy: try-catch

Validate before calling

// Ensure a fresh token per download and that it is not already cancelled
if opts.cancel_token.is_cancelled() {
    anyhow::bail!("Cancel token already triggered before download started");
}

Try / catch

if let Err(e) = p2p::download(&info, &opts, tx).await {
    if e.to_string().contains("Download cancelled") {
        // expected user abort: clean up UI state, no error toast
    } else {
        return Err(e);
    }
}

Prevention

When it happens

Trigger: Calling download() and cancelling the CancellationToken passed via DownloadOptions.cancel_token mid-transfer — e.g. the user presses a stop/cancel button in the UI.

Common situations: User aborts a slow P2P transfer; app shutdown cancels in-flight downloads; a UI timeout cancels a stalled transfer.

Related errors


AI-assisted analysis of tonhowtf/omniget@8600b91f42 (2026-09-12). Data as JSON: /api/errors/a1e682646de7184c. Report an issue: GitHub.

Appendix: source

Thrown at src-tauri/omniget-core/src/platforms/p2p.rs:164

        write_half.write_all(b"OK\n").await?;
        write_half.flush().await?;

        let _ = progress.send(ProgressUpdate::percent(0.0)).await;

        let sanitized = sanitize_filename::sanitize(&file_name);
        let output_path = opts.output_dir.join(&sanitized);
        if let Some(parent) = output_path.parent() {
            tokio::fs::create_dir_all(parent).await?;
        }

        let mut file = File::create(&output_path).await?;
        let mut received: u64 = 0;
        let mut buf = vec![0u8; CHUNK_SIZE];

        while received < file_size {
            if opts.cancel_token.is_cancelled() {
                let _ = tokio::fs::remove_file(&output_path).await;
                anyhow::bail!("Download cancelled");
            }

            let to_read = ((file_size - received) as usize).min(CHUNK_SIZE);
            let n = reader.read(&mut buf[..to_read]).await?;
            if n == 0 {
                break;
            }

            file.write_all(&buf[..n]).await?;
            received += n as u64;

            if file_size > 0 {
                let pct = (received as f64 / file_size as f64) * 100.0;
                let _ = progress.send(ProgressUpdate::percent(pct)).await;
            }
        }

        file.flush().await?;

View on GitHub (pinned to 8600b91f42)