tonhowtf/omniget · error

chave nao encontrada

Error message

chave nao encontrada

What it means

ai_keys::get scans the persisted key list for an entry with the given id and fails with "chave nao encontrada" ("key not found") when no entry matches. The id is treated as a resource identifier; a miss is a lookup failure on the stored key registry.

Solutions

  1. List existing keys (load()/list API) and confirm the id before calling get
  2. Refresh stale ids in the UI after any delete/upsert operation
  3. Verify the keys JSON file still exists and contains the expected entries
  4. Pass the exact KeyEntry::id string, not a provider name or label

Example fix

// before
let entry = get(&id).await?;
// after
let Some(entry) = list().into_iter().find(|e| e.id == id) else {
    return Err(anyhow!("chave nao encontrada: {} — liste as chaves e use um id valido", id));
};
Defensive patterns

Strategy: validation

Validate before calling

fn key_exists(id: &str) -> bool { load().iter().any(|e| e.id == id) }
// call before get():
if !key_exists(id) { return Err(anyhow!("id desconhecido: {}", id)); }

Try / catch

match get(&id).await {
    Err(e) if e.to_string() == "chave nao encontrada" => refresh_and_reselect_key(),
    other => handle(other),
}

Prevention

When it happens

Trigger: Calling get (directly or via entry_with_secret, balance, use_in_app, page_images, win_list) with an id that is not in the stored list — typically a stale id after the key was deleted or the store file was reset.

Common situations: UI holding an id from before the keys file was deleted/moved; caller passing the provider name instead of the id; multiple app instances where one deleted the key.

Understand the failure class

Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.

Related errors


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

Appendix: source

Thrown at src-tauri/omniget-core/src/core/tools/ai_keys.rs:243

    std::fs::rename(&tmp, &p)?;
    Ok(())
}

pub fn list() -> Vec<KeyView> {
    let _g = LOCK.lock().unwrap_or_else(|e| e.into_inner());
    load().iter().map(KeyEntry::view).collect()
}

/// Entrada completa (com segredo) para uso interno do app.
pub fn entry_with_secret(id: &str) -> anyhow::Result<KeyEntry> {
    get(id)
}

fn get(id: &str) -> anyhow::Result<KeyEntry> {
    load()
        .into_iter()
        .find(|e| e.id == id)
        .ok_or_else(|| anyhow!("chave nao encontrada"))
}

fn update<F: FnOnce(&mut KeyEntry)>(id: &str, f: F) -> anyhow::Result<KeyView> {
    let _g = LOCK.lock().unwrap_or_else(|e| e.into_inner());
    let mut list = load();
    let e = list
        .iter_mut()
        .find(|e| e.id == id)
        .ok_or_else(|| anyhow!("chave nao encontrada"))?;
    f(e);
    let v = e.view();
    save(&list)?;
    Ok(v)
}

/// Cria ou atualiza. Chave/token vazios mantêm o valor guardado.
pub fn upsert(mut entry: KeyEntry) -> anyhow::Result<KeyView> {
    let _g = LOCK.lock().unwrap_or_else(|e| e.into_inner());

View on GitHub (pinned to 8600b91f42)