{"record":{"id":"cfc9cf354aa7409f","repo":"tonhowtf/omniget","slug":"invalid-p2p-url-mod","errorCode":null,"errorMessage":"Invalid P2P URL: {}","messagePattern":"Invalid P2P URL: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-tauri/src/platforms/p2p/mod.rs","lineNumber":78,"sourceCode":"}\n\n#[async_trait]\nimpl PlatformDownloader for P2pDownloader {\n    fn name(&self) -> &str {\n        \"p2p\"\n    }\n\n    fn can_handle(&self, url: &str) -> bool {\n        if let Some(code) = url.strip_prefix(\"p2p:\") {\n            return words::is_valid_code(code);\n        }\n        false\n    }\n\n    async fn get_media_info(&self, url: &str) -> anyhow::Result<MediaInfo> {\n        let code = url\n            .strip_prefix(\"p2p:\")\n            .ok_or_else(|| anyhow!(\"Invalid P2P URL: {}\", url))?;\n\n        if !words::is_valid_code(code) {\n            anyhow::bail!(\"Invalid share code: {}\", code);\n        }\n\n        let title = format!(\"P2P Transfer ({})\", &code[..code.len().min(30)]);\n\n        Ok(MediaInfo {\n            title,\n            author: \"P2P Transfer\".to_string(),\n            platform: \"p2p\".to_string(),\n            duration_seconds: None,\n            thumbnail_url: None,\n            available_qualities: vec![VideoQuality {\n                label: \"Original\".to_string(),\n                width: 0,\n                height: 0,\n                url: url.to_string(),","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/src/platforms/p2p/mod.rs#L60-L96","documentation":"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.","triggerScenarios":"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).","commonSituations":"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:`).","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."],"exampleFix":"// before\nlet code = url\n    .strip_prefix(\"p2p:\")\n    .ok_or_else(|| anyhow!(\"Invalid P2P URL: {}\", url))?;\n// after\nlet normalized = url.trim();\nlet code = normalized\n    .strip_prefix(\"p2p:\")\n    .or_else(|| if words::is_valid_code(normalized) { Some(normalized) } else { None })\n    .ok_or_else(|| anyhow!(\"Invalid P2P URL: {} (expected 'p2p:<share-code>')\", url))?;","handlingStrategy":"validation","validationCode":"// Rust: validate scheme before dispatching to the P2P platform\nfn is_p2p_url(url: &str) -> bool {\n    url.trim().starts_with(\"p2p:\")\n}\nif !is_p2p_url(url) { return Err(anyhow!(\"not a p2p URL\")); }","typeGuard":"// Rust\nfn as_p2p_code(url: &str) -> Option<&str> {\n    url.trim().strip_prefix(\"p2p:\")\n}","tryCatchPattern":"match platform.get_media_info(url).await {\n    Err(e) if e.to_string().starts_with(\"Invalid P2P URL\") => {\n        eprintln!(\"Expected a p2p:<share-code> URL, got: {url}\");\n    }\n    other => other?,\n}","preventionTips":["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)"],"tags":["url","validation","p2p","input"],"backgroundTag":"invalid-url-format","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"}