tonhowtf/omniget · error

Invalid P2P URL

Error message

Invalid P2P URL

What it means

In download, the MediaInfo URL is expected to still carry the `p2p:` scheme so the share code can be extracted. If the stored/propagated URL lost the prefix, strip_prefix fails and this error is thrown. Unlike error 1122 this happens on the download path, after get_media_info already validated the URL.

Solutions

  1. Ensure the MediaInfo produced by get_media_info is passed to download unmodified, keeping the `p2p:` prefix intact.
  2. Check any code that persists or transforms queue entries for accidental prefix stripping.
  3. Log the offending URL at the error site to identify which stage corrupted it.
  4. If constructing MediaInfo elsewhere, always format the url as format!("p2p:{}", code).

Example fix

// before
let code = url
    .strip_prefix("p2p:")
    .ok_or_else(|| anyhow!("Invalid P2P URL"))?;
// after
let code = url
    .strip_prefix("p2p:")
    .ok_or_else(|| anyhow!("Invalid P2P URL: expected 'p2p:<code>', got '{}'", url))?;
Defensive patterns

Strategy: validation

Validate before calling

// Rust: check MediaInfo URL before calling download
if !info.url.starts_with("p2p:") {
    return Err(anyhow!("MediaInfo url lost p2p: prefix: {:?}", info.url));
}

Try / catch

match download(...).await {
    Err(e) if e.to_string().contains("Invalid P2P URL") => {
        tracing::error!("MediaInfo.url was mutated between fetch and download: {e:#}");
    }
    other => other?,
}

Prevention

When it happens

Trigger: download() reads the MediaInfo built earlier; the `url` field no longer starts with `p2p:` (e.g. the prefix was stripped, replaced, or the MediaInfo was constructed elsewhere without the scheme).

Common situations: A queue entry persisted with a mutated URL; another code path builds MediaInfo with a bare code; user-edited URL; scheme lost during serialization/normalization between the fetch and download stages.

Understand the failure class

Background: "Invalid URL" errors: why new URL(), URI.parse, and reqwest::Url reject your string — missing scheme, whitespace, and bad path format — this error's family across 39 libraries.

Related errors


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

Appendix: source

Thrown at src-tauri/src/platforms/p2p/mod.rs:117

            media_type: MediaType::Video,
            file_size_bytes: None,
        })
    }

    async fn download(
        &self,
        info: &MediaInfo,
        opts: &DownloadOptions,
        progress: mpsc::Sender<ProgressUpdate>,
    ) -> anyhow::Result<DownloadResult> {
        let url = match info.available_qualities.first() {
            Some(q) => &q.url,
            None => anyhow::bail!("No URL found in MediaInfo"),
        };

        let code = url
            .strip_prefix("p2p:")
            .ok_or_else(|| anyhow!("Invalid P2P URL"))?;

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

        tracing::info!("[p2p] connecting to relay for code: {}", code);

        let stream = connect_relay().await?;
        let (read_half, mut write_half) = tokio::io::split(stream);
        let mut reader = BufReader::new(read_half);

        write_half
            .write_all(format!("RECV {}\n", code).as_bytes())
            .await?;
        write_half.flush().await?;

        let response = read_line(&mut reader).await?;
        check_relay_error(&response)?;
        if response != "READY" {
            anyhow::bail!("Unexpected relay response: {}", response);

View on GitHub (pinned to 8600b91f42)