tonhowtf/omniget · error

modo desconhecido

Error message

modo desconhecido: {}

What it means

Thrown by SpriteOptions::run when opts.mode is not one of "slice", "pack", or "batch". The mode string is dispatched with match on as_str(); anything else yields this error including the offending value.

Solutions

  1. Set opts.mode to exactly "slice", "pack", or "batch" (lowercase).
  2. Normalize/validate the mode string at the boundary (UI/form) before constructing SpriteOptions.
  3. If migrating from older configs, map legacy mode names to the new ones.
  4. Parse the mode into an enum instead of free-form string to make invalid values unrepresentable.

Example fix

// before
let opts = SpriteOptions { mode: "Slice".into(), .. };
image_sprite::run(&opts, &progress)?; // modo desconhecido: Slice
// after
let mode = mode.to_lowercase();
assert!(matches!(mode.as_str(), "slice" | "pack" | "batch"));
let opts = SpriteOptions { mode, .. };
image_sprite::run(&opts, &progress)?;
Defensive patterns

Strategy: type-guard

Validate before calling

fn is_valid_mode(m: &str) -> bool { matches!(m, "slice" | "pack" | "batch") }
// call run() only if is_valid_mode(&opts.mode)

Type guard

enum SpriteMode { Slice, Pack, Batch }
fn parse_mode(m: &str) -> Option<SpriteMode> {
    match m {
        "slice" => Some(SpriteMode::Slice),
        "pack" => Some(SpriteMode::Pack),
        "batch" => Some(SpriteMode::Batch),
        _ => None,
    }
}

Try / catch

match image_sprite::run(&opts, &progress) {
    Err(e) if e.to_string().starts_with("modo desconhecido") => {
        eprintln!("use slice, pack ou batch (recebido: {e})");
    }
    other => other?,
}

Prevention

When it happens

Trigger: Calling image_sprite::run with SpriteOptions.mode set to a typo (e.g. "Slice", "slices"), a localized string, or a stale serialized value from an older config/UI version.

Common situations: UI sending an untranslated mode label; persisted settings from a renamed mode; hand-written test or CLI input using the wrong casing.

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/52a0756045c92d9e. Report an issue: GitHub.

Appendix: source

Thrown at src-tauri/omniget-core/src/core/tools/image_sprite.rs:616

    Ok(SpriteResult {
        mode: "batch".into(),
        count: outputs.len() as u32,
        outputs,
        frames,
        sheet: None,
        atlas: None,
        width: 0,
        height: 0,
        skipped,
    })
}

pub fn run(opts: &SpriteOptions, progress: &ProgressFn) -> anyhow::Result<SpriteResult> {
    match opts.mode.as_str() {
        "slice" => slice(opts, progress),
        "pack" => pack(opts, progress),
        "batch" => batch(opts, progress),
        other => Err(anyhow!("modo desconhecido: {}", other)),
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    fn solid(w: u32, h: u32, c: [u8; 4]) -> RgbaImage {
        RgbaImage::from_pixel(w, h, image::Rgba(c))
    }

    /// Quadro com um pixel diferente em cada canto, para o round-trip pegar
    /// qualquer deslocamento de um px.
    fn frame(i: u32) -> RgbaImage {
        let mut img = solid(16, 16, [(i * 20) as u8, 40, 200 - (i * 7) as u8, 255]);
        img.put_pixel(0, 0, image::Rgba([255, 255, 255, 255]));
        img.put_pixel(15, 15, image::Rgba([0, 0, 0, 255]));
        img

View on GitHub (pinned to 8600b91f42)