tonhowtf/omniget · error

Invalid share code

Error message

Invalid share code: {}

What it means

p2p.rs throws this in get_media_info() when the URL's share code fails super::p2p_words::is_valid_code(). The URL correctly uses the p2p: scheme (that check already passed), but the code itself is not a valid word-encoded share code, so the input is rejected before any relay contact.

Solutions

  1. Re-enter the share code exactly as generated — check each word against the p2p_words list, casing and separators.
  2. Copy-paste the full code instead of retyping it; ensure nothing was truncated at the ends.
  3. Confirm the code was generated by the same app/protocol version (word lists can differ across versions).
  4. Run is_valid_code(code) client-side before submitting the URL to give immediate feedback.

Example fix

// before
let info = p2p.get_media_info(user_input).await?;
// after
let code = user_input.strip_prefix("p2p:").unwrap_or(&user_input);
if !omniget_core::platforms::p2p_words::is_valid_code(code) {
    return Err(anyhow!("'{}' is not a valid share code; re-check the words", code));
}
let info = p2p.get_media_info(user_input).await?;
Defensive patterns

Strategy: validation

Validate before calling

// before calling get_media_info
let code = url.strip_prefix("p2p:").ok_or_else(|| anyhow!("not a p2p: url"))?;
if !p2p_words::is_valid_code(code) {
    eprintln!("invalid share code: {code}");
}

Type guard

// Rust
fn valid_p2p_url(url: &str) -> Option<()> {
    let code = url.strip_prefix("p2p:")?;
    if p2p_words::is_valid_code(code) { Some(()) } else { None }
}

Try / catch

match p2p.get_media_info(url).await {
    Err(e) if e.to_string().starts_with("Invalid share code") => {
        prompt_user_to_reenter_code();
    }
    other => other,
}

Prevention

When it happens

Trigger: get_media_info(url) where url.strip_prefix("p2p:") succeeds but p2p_words::is_valid_code(code) returns false at p2p.rs:79 — wrong word count, words outside the p2p_words dictionary, wrong casing/spacing, or stray characters in the code.

Common situations: User hand-types the share code and misspells a word; code truncated when copied; extra whitespace or punctuation included; a code from a different app/version using another word list; localizer autocorrects words.

Understand the failure class

Background: "invalid id" errors: invalid identifier format — why libraries reject IDs before lookup, and how to fix them — this error's family across 37 libraries.

Related errors


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

Appendix: source

Thrown at src-tauri/omniget-core/src/platforms/p2p.rs:79

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 super::p2p_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 !super::p2p_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(),
                format: "p2p".to_string(),
            }],
            media_type: MediaType::Video,

View on GitHub (pinned to 8600b91f42)