tonhowtf/omniget · error
Invalid P2P URL
Error message
Invalid P2P URL: {} What it means
get_media_info requires P2P URLs to carry the `p2p:` scheme prefix. If the URL passed to the platform's get_media_info does not start with `p2p:`, strip_prefix returns None and this error is thrown. It guards against dispatching non-P2P URLs into the P2P handler.
Solutions
- Ensure the URL string starts exactly with `p2p:` before dispatching to the P2P platform handler.
- Fix the caller's URL-routing logic so it selects the correct platform for the URL scheme.
- Normalize input: trim whitespace and lowercase the scheme before calling get_media_info.
- If accepting bare codes, prepend `p2p:` before invoking get_media_info.
Example fix
// before
let code = url
.strip_prefix("p2p:")
.ok_or_else(|| anyhow!("Invalid P2P URL: {}", url))?;
// after
let normalized = url.trim();
let code = normalized
.strip_prefix("p2p:")
.or_else(|| if words::is_valid_code(normalized) { Some(normalized) } else { None })
.ok_or_else(|| anyhow!("Invalid P2P URL: {} (expected 'p2p:<share-code>')", url))?; Defensive patterns
Strategy: validation
Validate before calling
// Rust: validate scheme before dispatching to the P2P platform
fn is_p2p_url(url: &str) -> bool {
url.trim().starts_with("p2p:")
}
if !is_p2p_url(url) { return Err(anyhow!("not a p2p URL")); } Type guard
// Rust
fn as_p2p_code(url: &str) -> Option<&str> {
url.trim().strip_prefix("p2p:")
} Try / catch
match platform.get_media_info(url).await {
Err(e) if e.to_string().starts_with("Invalid P2P URL") => {
eprintln!("Expected a p2p:<share-code> URL, got: {url}");
}
other => other?,
} Prevention
- Route URLs to platforms by explicit scheme matching before calling get_media_info
- Normalize/trim/lowercase scheme on all user input
- Document the p2p: URL format in the public API
- Add unit tests for malformed URL variants (missing prefix, wrong case, whitespace)
When it happens
Trigger: get_media_info(url) is called with a string lacking the `p2p:` prefix — e.g. an https:// URL, an empty string, a bare share code without the scheme, or `p2p` misspelled (e.g. `P2P:code`, `p2p:code ` with leading whitespace).
Common situations: Caller routing logic passes a non-P2P URL to the P2P platform by mistake; user pastes a share code without the `p2p:` prefix; URL normalization stripped or mangled the scheme; case-sensitivity mismatch (`P2P:` vs `p2p:`).
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/cfc9cf354aa7409f.
Report an issue: GitHub.
Appendix: source
Thrown at src-tauri/src/platforms/p2p/mod.rs:78
}
#[async_trait]
impl PlatformDownloader for P2pDownloader {
fn name(&self) -> &str {
"p2p"
}
fn can_handle(&self, url: &str) -> bool {
if let Some(code) = url.strip_prefix("p2p:") {
return words::is_valid_code(code);
}
false
}
async fn get_media_info(&self, url: &str) -> anyhow::Result<MediaInfo> {
let code = url
.strip_prefix("p2p:")
.ok_or_else(|| anyhow!("Invalid P2P URL: {}", url))?;
if !words::is_valid_code(code) {
anyhow::bail!("Invalid share code: {}", code);
}
let title = format!("P2P Transfer ({})", &code[..code.len().min(30)]);
Ok(MediaInfo {
title,
author: "P2P Transfer".to_string(),
platform: "p2p".to_string(),
duration_seconds: None,
thumbnail_url: None,
available_qualities: vec![VideoQuality {
label: "Original".to_string(),
width: 0,
height: 0,
url: url.to_string(),View on GitHub (pinned to 8600b91f42)