{"record":{"id":"d35c3c696f9e2421","repo":"sigoden/aichat","slug":"no-rag","errorCode":null,"errorMessage":"No RAG","messagePattern":"No RAG","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/config/mod.rs","lineNumber":1377,"sourceCode":"                let rag_path = config.read().rag_file(name);\n                if !rag_path.exists() {\n                    if config.read().working_mode.is_cmd() {\n                        bail!(\"Unknown RAG '{name}'\")\n                    }\n                    Rag::init(config, name, &rag_path, &[], abort_signal).await?\n                } else {\n                    Rag::load(config, name, &rag_path)?\n                }\n            }\n        };\n        config.write().rag = Some(Arc::new(rag));\n        Ok(())\n    }\n\n    pub async fn edit_rag_docs(config: &GlobalConfig, abort_signal: AbortSignal) -> Result<()> {\n        let mut rag = match config.read().rag.clone() {\n            Some(v) => v.as_ref().clone(),\n            None => bail!(\"No RAG\"),\n        };\n\n        let document_paths = rag.document_paths();\n        let temp_file = temp_file(&format!(\"-rag-{}\", rag.name()), \".txt\");\n        tokio::fs::write(&temp_file, &document_paths.join(\"\\n\"))\n            .await\n            .with_context(|| format!(\"Failed to write to '{}'\", temp_file.display()))?;\n        let editor = config.read().editor()?;\n        edit_file(&editor, &temp_file)?;\n        let new_document_paths = tokio::fs::read_to_string(&temp_file)\n            .await\n            .with_context(|| format!(\"Failed to read '{}'\", temp_file.display()))?;\n        let new_document_paths = new_document_paths\n            .split('\\n')\n            .filter_map(|v| {\n                let v = v.trim();\n                if v.is_empty() {\n                    None","sourceCodeStart":1359,"sourceCodeEnd":1395,"githubUrl":"https://github.com/sigoden/aichat/blob/82976d349ad97ac9aae0655ad631dace5e2a6385/src/config/mod.rs#L1359-L1395","documentation":"Thrown by `GlobalConfig::edit_rag_docs` in src/config/mod.rs:1377 when there is no active RAG session: `config.read().rag` is `None`. Editing RAG documents only makes sense inside an active RAG session, so the function fails immediately instead of guessing which RAG to edit.","triggerScenarios":"Calling `Config::edit_rag_docs(config, abort_signal)` (or the `.rag edit-docs`-style command) without having entered RAG mode first — i.e. `config.rag` was never set via `use_rag`/`Rag::load`, or was cleared by `exit_rag`.","commonSituations":"Running the edit-docs command in a fresh session; running it after `.exit rag`; assuming a previously used RAG persists across sessions when it is only held in the in-memory config.","solutions":["Enter RAG mode first (e.g. `.rag <name>` / `use_rag`) so `config.rag` is populated, then run edit-docs","Call `use_rag(config, Some(name), signal)` programmatically before `edit_rag_docs`","Check `config.read().rag.is_some()` before invoking and surface a friendlier message"],"exampleFix":"// before\nconfig.edit_rag_docs(signal).await?;\n// after\nif config.read().rag.is_none() {\n    config.use_rag(Some(\"mydocs\"), signal).await?;\n}\nconfig.edit_rag_docs(signal).await?;","handlingStrategy":"validation","validationCode":"if config.read().rag.is_none() {\n    bail!(\"No RAG loaded; run '.rag <name>' before editing documents\");\n}","typeGuard":null,"tryCatchPattern":"if let Err(e) = config.edit_rag_docs(signal).await {\n    if e.to_string() == \"No RAG\" {\n        eprintln!(\"Enter RAG mode first: .rag <name>\");\n        return Ok(());\n    }\n    return Err(e.into());\n}","preventionTips":["Enter RAG mode before any rag subcommand","Re-enter RAG mode at the start of each session — state does not persist across restarts","Wrap rag subcommands in a helper that ensures `use_rag` ran first"],"tags":["rag","missing-state","cli"],"backgroundTag":"resource-not-found","analyzedSha":"82976d349ad97ac9aae0655ad631dace5e2a6385","analyzedAt":"2026-09-09T18:33:06.139Z","contentChangedAt":"2026-09-09T18:33:06.139Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}