{"record":{"id":"3a4907c008b3b614","repo":"tonhowtf/omniget","slug":"could-not-extract-post-id-3a4907","errorCode":null,"errorMessage":"Could not extract post ID","messagePattern":"Could not extract post ID","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-tauri/src/platforms/reddit/mod.rs","lineNumber":415,"sourceCode":"            }\n        }\n\n        self.native_download(info, opts, progress).await\n    }\n}\n\nimpl RedditDownloader {\n    async fn fallback_ytdlp(&self, url: &str) -> anyhow::Result<MediaInfo> {\n        let ytdlp_path = crate::core::ytdlp::ensure_ytdlp().await?;\n        let json = crate::core::ytdlp::get_video_info(&ytdlp_path, url, &[]).await?;\n        crate::platforms::generic_ytdlp::GenericYtdlpDownloader::parse_video_info(&json)\n    }\n\n    async fn native_get_media_info(&self, url: &str) -> anyhow::Result<MediaInfo> {\n        let canonical = self.resolve_to_canonical(url).await?;\n\n        let post_id = Self::extract_post_id(&canonical)\n            .ok_or_else(|| anyhow!(\"Could not extract post ID\"))?;\n\n        let subreddit = Self::extract_subreddit(&canonical).unwrap_or_default();\n\n        let data = self.fetch_post_data(&post_id).await?;\n\n        let media = Self::parse_media(&data).ok_or_else(|| anyhow!(\"No media found in post\"))?;\n\n        let source_id = if subreddit.is_empty() {\n            post_id.clone()\n        } else {\n            format!(\"{}_{}\", subreddit.to_lowercase(), post_id)\n        };\n\n        let title = format!(\"reddit_{}\", source_id);\n\n        match media {\n            RedditMedia::Video {\n                video_url,","sourceCodeStart":397,"sourceCodeEnd":433,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/src/platforms/reddit/mod.rs#L397-L433","documentation":"native_get_media_info first canonicalizes the URL and then runs extract_post_id on it; if no post ID can be parsed from the canonical URL, the library aborts with this error before making any network request.","triggerScenarios":"Passing URLs that resolve to non-comment-permalink forms: subreddit pages, user pages, gallery/crosspost links where the ID is nested differently, old.reddit/share URLs with unexpected path shapes, or malformed input (empty string, non-Reddit URL).","commonSituations":"Users pasting a share link (reddit.com/share/...), a redd.it short link whose regex is unsupported, a live/thread URL, or a mobile app URL (reddit://); locale-prefixed or old.reddit variants the extractor misses.","solutions":["Log the canonical URL right before extract_post_id and extend its regex to cover the missed URL shape.","Normalize common forms first: strip query strings, handle redd.it/<id>, /comments/<id> anywhere in the path, and old.reddit/locale prefixes.","Reject non-post URLs early with a clear 'not a Reddit post URL' validation message.","Resolve share/redirect links (follow HTTP redirects) to a canonical /comments/<id> URL before extraction.","Add unit tests for the URL shapes your users actually paste."],"exampleFix":"// before\nlet post_id = Self::extract_post_id(&canonical)\n    .ok_or_else(|| anyhow!(\"Could not extract post ID\"))?;\n// after\nlet post_id = Self::extract_post_id(&canonical).or_else(|| {\n    regex::Regex::new(r\"(?:comments|redd\\.it)/([a-z0-9]{4,10})\")\n        .ok()\n        .and_then(|re| re.captures(&canonical))\n        .and_then(|c| c.get(1).map(|m| m.as_str().to_string()))\n}).ok_or_else(|| anyhow!(\"Could not extract post ID from URL: {}\", canonical))?;","handlingStrategy":"validation","validationCode":"// regex pre-check before calling the API\nlet re = regex::Regex::new(r\"(?:comments/|redd\\.it/)([a-z0-9]{4,10})\").unwrap();\nif !re.is_match(&url) { return Err(\"not a Reddit post URL\"); }","typeGuard":"fn extract_post_id_url_guard(url: &str) -> Option<String> {\n    regex::Regex::new(r\"(?:comments/|redd\\.it/)([a-z0-9]{4,10})\")\n        .ok()\n        .and_then(|re| re.captures(url))\n        .and_then(|c| c.get(1).map(|m| m.as_str().to_string()))\n}","tryCatchPattern":"match get_media_info(&user_url).await {\n    Err(e) if e.to_string().contains(\"Could not extract post ID\") => notify(\"Please paste a direct Reddit post link\"),\n    other => other,\n}","preventionTips":["Normalize URLs (strip query strings, resolve share/redd.it links) before extraction","Follow redirects on share links to obtain a canonical /comments/<id> URL","Cover old.reddit and locale-prefixed hosts in the extractor regex","Keep a unit-test table of real user-pasted URL shapes"],"tags":["reddit","url-parsing","validation"],"backgroundTag":"invalid-identifier-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"}