tonhowtf/omniget · error · anyhow::Error

Could not extract post ID

Error message

Could not extract post ID

What it means

Raised in `get_media_info` when `extract_post_id` returns None for the URL resolved from a share link. `extract_post_id` only matches path shapes `/p/<id>`, `/reel/<id>`, `/reels/<id>`, `/tv/<id>`; any other resolved URL shape has no extractable post ID, so the flow aborts.

Solutions

  1. Log the resolved URL (`resolve_share_link` output) and check what path shape it actually redirects to
  2. Ensure the share link resolves to /p/, /reel/, /reels/ or /tv/ before calling; otherwise surface an 'unsupported URL' message to the user
  3. Extend `extract_post_id`'s match arms if Instagram added a new canonical path prefix
  4. Handle the 'Could not resolve share link' error upstream so dead share links never reach ID extraction

Example fix

// before
let post_id = Self::extract_post_id(&resolved)
    .ok_or_else(|| anyhow!("Could not extract post ID"))?;
// after
let post_id = Self::extract_post_id(&resolved).ok_or_else(|| {
    anyhow!("Could not extract post ID from resolved URL: {resolved}")
})?;
Defensive patterns

Strategy: validation

Validate before calling

fn looks_like_post_url(url: &str) -> bool {
    url::Url::parse(url).ok()
        .map(|u| {
            let segs: Vec<&str> = u.path().split('/').filter(|s| !s.is_empty()).collect();
            matches!(segs.first(), Some(&"p") | Some(&"reel") | Some(&"reels") | Some(&"tv"))
                && segs.get(1).map_or(false, |s| !s.is_empty())
        })
        .unwrap_or(false)
}

Type guard

fn extract_post_id_guard(url: &str) -> Option<String> {
    let parsed = url::Url::parse(url).ok()?;
    let segs: Vec<&str> = parsed.path().split('/').filter(|s| !s.is_empty()).collect();
    match segs.first() {
        Some(&"p") | Some(&"reel") | Some(&"reels") | Some(&"tv") => segs.get(1).map(|s| s.to_string()),
        _ => None,
    }
}

Try / catch

match downloader.get_media_info(&share_url).await {
    Err(e) if e.to_string().contains("Could not extract post ID") => {
        tracing::warn!("share link resolved to unsupported path; ask user for canonical post URL");
        Err(anyhow!("Share link did not point to a post/reel; paste the direct /p/ or /reel/ URL"))
    }
    other => other,
}

Prevention

When it happens

Trigger: Calling `get_media_info` with a `/share/<id>` link whose redirect lands on a URL that does not match the supported post path patterns — e.g. redirect to a profile page, login page, or a new Instagram path scheme.

Common situations: Share links redirecting to `/stories/` or `/explore/` pages; expired share links bouncing to the login wall; Instagram introducing a new canonical path segment the parser doesn't know; malformed URLs that parse but have no media segment.

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/46509495f1012200. Report an issue: GitHub.

Appendix: source

Thrown at src-tauri/src/platforms/instagram/mod.rs:675

                return host == "instagram.com"
                    || host.ends_with(".instagram.com")
                    || host == "ddinstagram.com"
                    || host.ends_with(".ddinstagram.com");
            }
        }
        false
    }

    async fn get_media_info(&self, url: &str) -> anyhow::Result<MediaInfo> {
        if Self::is_story_url(url) {
            return Err(anyhow!(
                "Instagram Stories are not supported. Only public posts, reels and carousels."
            ));
        }

        let post_id = if let Some(share_id) = Self::extract_share_id(url) {
            let resolved = self.resolve_share_link(&share_id).await?;
            Self::extract_post_id(&resolved).ok_or_else(|| anyhow!("Could not extract post ID"))?
        } else {
            Self::extract_post_id(url).ok_or_else(|| anyhow!("Could not extract post ID"))?
        };

        let filename_base = format!("instagram_{}", post_id);

        let embed_result = self.request_embed(&post_id).await;
        let media = match embed_result {
            Ok(data) => Self::extract_media_from_embed(&data),
            Err(_embed_err) => match self.request_gql(&post_id).await {
                Ok(data) => Self::extract_media_from_gql(&data),
                Err(_gql_err) => {
                    return self.fallback_ytdlp(url, &post_id).await;
                }
            },
        };

        let media = match media {

View on GitHub (pinned to 8600b91f42)