{"record":{"id":"e05536eb7f969598","repo":"tonhowtf/omniget","slug":"chave-nao-encontrada","errorCode":null,"errorMessage":"chave nao encontrada","messagePattern":"chave nao encontrada","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/core/tools/ai_keys.rs","lineNumber":243,"sourceCode":"    std::fs::rename(&tmp, &p)?;\n    Ok(())\n}\n\npub fn list() -> Vec<KeyView> {\n    let _g = LOCK.lock().unwrap_or_else(|e| e.into_inner());\n    load().iter().map(KeyEntry::view).collect()\n}\n\n/// Entrada completa (com segredo) para uso interno do app.\npub fn entry_with_secret(id: &str) -> anyhow::Result<KeyEntry> {\n    get(id)\n}\n\nfn get(id: &str) -> anyhow::Result<KeyEntry> {\n    load()\n        .into_iter()\n        .find(|e| e.id == id)\n        .ok_or_else(|| anyhow!(\"chave nao encontrada\"))\n}\n\nfn update<F: FnOnce(&mut KeyEntry)>(id: &str, f: F) -> anyhow::Result<KeyView> {\n    let _g = LOCK.lock().unwrap_or_else(|e| e.into_inner());\n    let mut list = load();\n    let e = list\n        .iter_mut()\n        .find(|e| e.id == id)\n        .ok_or_else(|| anyhow!(\"chave nao encontrada\"))?;\n    f(e);\n    let v = e.view();\n    save(&list)?;\n    Ok(v)\n}\n\n/// Cria ou atualiza. Chave/token vazios mantêm o valor guardado.\npub fn upsert(mut entry: KeyEntry) -> anyhow::Result<KeyView> {\n    let _g = LOCK.lock().unwrap_or_else(|e| e.into_inner());","sourceCodeStart":225,"sourceCodeEnd":261,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/core/tools/ai_keys.rs#L225-L261","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["List existing keys (load()/list API) and confirm the id before calling get","Refresh stale ids in the UI after any delete/upsert operation","Verify the keys JSON file still exists and contains the expected entries","Pass the exact KeyEntry::id string, not a provider name or label"],"exampleFix":"// before\nlet entry = get(&id).await?;\n// after\nlet Some(entry) = list().into_iter().find(|e| e.id == id) else {\n    return Err(anyhow!(\"chave nao encontrada: {} — liste as chaves e use um id valido\", id));\n};","handlingStrategy":"validation","validationCode":"fn key_exists(id: &str) -> bool { load().iter().any(|e| e.id == id) }\n// call before get():\nif !key_exists(id) { return Err(anyhow!(\"id desconhecido: {}\", id)); }","typeGuard":null,"tryCatchPattern":"match get(&id).await {\n    Err(e) if e.to_string() == \"chave nao encontrada\" => refresh_and_reselect_key(),\n    other => handle(other),\n}","preventionTips":["Always source ids from a fresh list() call, never from cached UI state","Invalidate cached ids after any delete operation","Distinguish provider name from entry id in the UI"],"tags":["lookup","not-found","ai-keys"],"backgroundTag":"record-not-found","analyzedSha":"8600b91f4246848bac346874daa9e61c1fc5677a","analyzedAt":"2026-09-12T14:29:19.317Z","contentChangedAt":"2026-09-12T14:29:19.317Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}