tonhowtf/omniget · error · anyhow::Error

formato desconhecido

Error message

formato desconhecido: {}

What it means

write_posts in the X (Twitter) export module validates the `format` argument against a fixed set of accepted values: json, csv, md/markdown, html, txt/text. Any other string hits the catch-all arm and the function bails with this error before any file is written. It is a pure input-validation error — nothing was persisted to disk.

Solutions

  1. Use one of the supported format strings exactly: "json", "csv", "md", "markdown", "html", "txt", or "text".
  2. Normalize the input first (trim and lowercase) before passing it to write_posts.
  3. Validate the format at the CLI/config boundary with an enum or allowlist so invalid values are rejected early.
  4. Check for typos in the format value; matching is exact and case-sensitive.
  5. If a new format is genuinely needed, add a corresponding posts_<format> function and match arm in write_posts.

Example fix

// before
write_posts(&posts, title, dest, "YAML")?;
// after
let fmt = format.trim().to_lowercase();
match fmt.as_str() {
    "json" | "csv" | "md" | "markdown" | "html" | "txt" | "text" => {}
    other => panic!("unsupported format: {}", other),
}
write_posts(&posts, title, dest, &fmt)?;
Defensive patterns

Strategy: validation

Validate before calling

const FORMATS: [&str; 7] = ["json", "csv", "md", "markdown", "html", "txt", "text"];
let fmt = format.trim().to_lowercase();
if !FORMATS.contains(&fmt.as_str()) {
    anyhow::bail!("unsupported format: {} (use one of {:?})", fmt, FORMATS);
}

Type guard

fn is_supported_format(f: &str) -> bool {
    matches!(f.trim().to_lowercase().as_str(), "json" | "csv" | "md" | "markdown" | "html" | "txt" | "text")
}

Prevention

When it happens

Trigger: Calling write_posts(posts, title, dest, format) with a format string outside the supported set, e.g. "yaml", "JSON" (uppercase, matching is exact), "rtf", or a typo like "markdwon".

Common situations: Passing a user-supplied format option straight from a CLI flag or config file without normalizing case/whitespace; assuming other formats (yaml, xml) are supported; capitalization mismatch since matching is case-sensitive.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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

Appendix: source

Thrown at src-tauri/omniget-core/src/core/tools/x/export.rs:237

        t = html_escape(title),
        b = body
    )
}

/// Escreve `posts` em `dest` no formato pedido e devolve o caminho.
pub fn write_posts(
    posts: &[XPost],
    format: &str,
    dest: &std::path::Path,
    title: &str,
) -> anyhow::Result<String> {
    let content = match format {
        "json" => serde_json::to_string_pretty(posts)?,
        "csv" => posts_csv(posts),
        "md" | "markdown" => posts_markdown(title, posts),
        "html" => posts_html(title, posts),
        "txt" | "text" => posts_text(posts),
        other => anyhow::bail!("formato desconhecido: {}", other),
    };
    if let Some(parent) = dest.parent() {
        std::fs::create_dir_all(parent)?;
    }
    std::fs::write(dest, content)?;
    Ok(dest.to_string_lossy().to_string())
}

pub fn write_users(
    users: &[XUser],
    format: &str,
    dest: &std::path::Path,
) -> anyhow::Result<String> {
    let content = match format {
        "json" => serde_json::to_string_pretty(users)?,
        "csv" => users_csv(users),
        "md" | "markdown" | "txt" => {
            users

View on GitHub (pinned to 8600b91f42)