{"record":{"id":"6f42da3741dee972","repo":"sigoden/aichat","slug":"unknown-rag-name","errorCode":null,"errorMessage":"Unknown RAG '{name}'","messagePattern":"Unknown RAG '(.+?)'","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/config/mod.rs","lineNumber":1362,"sourceCode":"    ) -> Result<()> {\n        if config.read().agent.is_some() {\n            bail!(\"Cannot perform this operation because you are using a agent\")\n        }\n        let rag = match rag {\n            None => {\n                let rag_path = config.read().rag_file(TEMP_RAG_NAME);\n                if rag_path.exists() {\n                    remove_file(&rag_path).with_context(|| {\n                        format!(\"Failed to cleanup previous '{TEMP_RAG_NAME}' rag\")\n                    })?;\n                }\n                Rag::init(config, TEMP_RAG_NAME, &rag_path, &[], abort_signal).await?\n            }\n            Some(name) => {\n                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();","sourceCodeStart":1344,"sourceCodeEnd":1380,"githubUrl":"https://github.com/sigoden/aichat/blob/82976d349ad97ac9aae0655ad631dace5e2a6385/src/config/mod.rs#L1344-L1380","documentation":"Thrown by `GlobalConfig::use_rag` in src/config/mod.rs:1362 when an explicitly named RAG is requested but no RAG file exists at the path returned by `config.rag_file(name)`, AND the current working mode is a command (non-interactive) mode. In interactive mode the library instead initializes a brand-new RAG with that name; in cmd mode it fails fast so scripts get a clear 'unknown RAG' signal.","triggerScenarios":"Calling `use_rag(config, Some(name), abort_signal)` where `rag_file(name)` does not exist and `config.working_mode.is_cmd()` is true — e.g. a one-shot CLI invocation like `--rag mydocs` where 'mydocs' was never created.","commonSituations":"Typo in the RAG name in CI scripts or CLI flags; referencing a RAG created on another machine (RAG files are machine-local); running a non-interactive command before ever initializing the RAG interactively.","solutions":["Create the RAG first by running the same command in interactive mode (it will initialize it), or use the rag-creation command","Fix the RAG name typo / point to an existing RAG file","Copy or regenerate the RAG file at the expected `rag_file(name)` path before running the command"],"exampleFix":"// before (cmd mode, RAG never created)\nconfig.use_rag(Some(\"mydocs\"), signal).await?;\n// after: ensure it exists or fall back to interactive init\nlet path = config.read().rag_file(\"mydocs\");\nif !path.exists() {\n    eprintln!(\"RAG 'mydocs' not found; initializing it first\");\n    Rag::init(&config, \"mydocs\", &path, &[], signal).await?;\n}\nconfig.use_rag(Some(\"mydocs\"), signal).await?;","handlingStrategy":"validation","validationCode":"let path = config.read().rag_file(name);\nif !path.exists() && config.read().working_mode.is_cmd() {\n    bail!(\"RAG '{name}' does not exist; initialize it in an interactive session first\");\n}","typeGuard":null,"tryCatchPattern":"match config.use_rag(Some(name), signal).await {\n    Err(e) if e.to_string().starts_with(\"Unknown RAG\") => {\n        eprintln!(\"No RAG named '{name}'. Available: {:?}\", list_rags());\n    }\n    r => r?,\n}","preventionTips":["Keep RAG names in a script variable or config rather than retyping them","Initialize named RAGs in interactive mode before using them in CI/cmd mode","Remember RAG files are machine-local; recreate them on new machines"],"tags":["rag","file-not-found","cli","scripting"],"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"}