tonhowtf/omniget · error · anyhow::Error

variante de ONNX Runtime desconhecida

Error message

variante de ONNX Runtime desconhecida: {id}

What it means

pick_asset resolves an explicit ONNX Runtime variant id via asset_by_id; when the caller passes a variant string that is not a known catalog id, it fails fast with 'variante de ONNX Runtime desconhecida' instead of silently falling back to auto-detection.

Solutions

  1. List valid variant ids from the onnxrt catalog (asset ids) and pass one exactly
  2. Use "auto" (or None/empty) to let auto_variant_id() pick the platform asset
  3. Update config/settings to remove the stale variant id after upgrading the app
  4. Add the desired platform asset to the catalog if it is genuinely missing

Example fix

// before
install_runtime(Some("win-x64-gpu115"))  // unknown id
// after
install_runtime(Some("win-x64-cuda12")) // id present in catalog
// or
install_runtime(None) // auto-detect
Defensive patterns

Strategy: validation

Validate before calling

// validate variant id against the catalog before calling install_runtime
fn is_known_variant(id: &str) -> bool {
    let id = id.trim();
    id.is_empty() || id == "auto" || onnxrt::asset_ids().contains(&id)
}
if !is_known_variant(user_variant) { eprintln!("unknown variant {user_variant}"); }

Type guard

fn valid_variant(v: &Option<String>) -> bool {
    v.as_deref().map(|s| {
        let s = s.trim();
        s.is_empty() || s == "auto" || onnxrt::asset_ids().contains(&s.to_string())
    }).unwrap_or(true)
}

Try / catch

match onnxrt::install_runtime(variant.as_deref()) {
    Err(e) if e.to_string().starts_with("variante de ONNX Runtime desconhecida") => {
        eprintln!("{} — valid: {}", e, onnxrt::asset_ids().join(", "));
        onnxrt::install_runtime(None)?; // fall back to auto
    }
    other => other?,
}

Prevention

When it happens

Trigger: install_runtime (or tests) called with variant=Some("...") where the trimmed string is non-empty and not "auto", but asset_by_id(id) finds no matching Asset.

Common situations: Typo in the variant id passed from settings/config; catalog updated after an upgrade so an old id no longer exists; user copy-pasted a variant name from another platform.

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/079f158da9c364d0. Report an issue: GitHub.

Appendix: source

Thrown at src-tauri/omniget-core/src/core/onnxrt.rs:164

            id: a.id.to_string(),
            label: a.label.to_string(),
            bytes: a.bytes,
            recommended: Some(a.id) == auto,
        })
        .collect()
}

fn asset_by_id(id: &str) -> Option<&'static Asset> {
    ASSETS.iter().find(|a| a.id == id)
}

fn pick_asset(variant: Option<&str>) -> anyhow::Result<&'static Asset> {
    let wanted = variant
        .map(|s| s.trim())
        .filter(|s| !s.is_empty() && *s != "auto");
    if let Some(id) = wanted {
        return asset_by_id(id)
            .ok_or_else(|| anyhow!("variante de ONNX Runtime desconhecida: {id}"));
    }
    let auto = auto_variant_id().ok_or_else(|| {
        anyhow!(
            "a Microsoft não publica ONNX Runtime pronto para este sistema; \
             instale a partir de um arquivo local (pacote `onnxruntime` do pip, por exemplo)"
        )
    })?;
    asset_by_id(auto).ok_or_else(|| anyhow!("variante {auto} sumiu do catálogo"))
}

pub fn target_dir() -> Option<PathBuf> {
    crate::core::paths::app_data_dir().map(|d| d.join("onnxruntime"))
}

pub fn target_path() -> Option<PathBuf> {
    target_dir().map(|d| d.join(lib_filename()))
}

View on GitHub (pinned to 8600b91f42)