{"record":{"id":"b99e7a27360b0206","repo":"sigoden/aichat","slug":"no-agent","errorCode":null,"errorMessage":"No agent","messagePattern":"No agent","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/config/mod.rs","lineNumber":1522,"sourceCode":"            } else {\n                agent.agent_prelude().map(|v| v.to_string())\n            }\n        });\n        config.write().rag = agent.rag();\n        config.write().agent = Some(agent);\n        if let Some(session) = session {\n            config.write().use_session(Some(&session))?;\n        } else {\n            config.write().init_agent_shared_variables()?;\n        }\n        Ok(())\n    }\n\n    pub fn agent_info(&self) -> Result<String> {\n        if let Some(agent) = &self.agent {\n            agent.export()\n        } else {\n            bail!(\"No agent\")\n        }\n    }\n\n    pub fn agent_banner(&self) -> Result<String> {\n        if let Some(agent) = &self.agent {\n            Ok(agent.banner())\n        } else {\n            bail!(\"No agent\")\n        }\n    }\n\n    pub fn edit_agent_config(&self) -> Result<()> {\n        let agent_name = match &self.agent {\n            Some(agent) => agent.name(),\n            None => bail!(\"No agent\"),\n        };\n        let agent_config_path = Config::agent_config_file(agent_name);\n        ensure_parent_exists(&agent_config_path)?;","sourceCodeStart":1504,"sourceCodeEnd":1540,"githubUrl":"https://github.com/sigoden/aichat/blob/82976d349ad97ac9aae0655ad631dace5e2a6385/src/config/mod.rs#L1504-L1540","documentation":"Thrown by GlobalConfig::agent_info() when `self.agent` is None. agent_info() exports the currently selected agent's configuration as a string, so without an agent selected there is nothing to export. It is a deliberate bail! rather than an Option because callers expect a Result<String>.","triggerScenarios":"Calling config.agent_info() (via a CLI subcommand like `aichat agent info` or `--agent-info`) before any agent has been selected with use_agent / set_agent, or after the configured agent failed to load.","commonSituations":"Running an agent-info command in a fresh installation where no agent is set in config.yaml; scripting agent info before `agent init`; config file present but the `agent` key is absent or null.","solutions":["Select an agent first (config.use_agent(Some(\"<name>\")) or the corresponding CLI command) before calling agent_info().","Guard the call: check config.read().agent.is_some() before invoking agent_info().","If no agent is intended, run `agent init <name>` to create one."],"exampleFix":"// before\nlet info = config.agent_info()?;\n// after\nif config.read().agent.is_none() {\n    eprintln!(\"No agent selected; run `agent init <name>` first\");\n    return Ok(());\n}\nlet info = config.agent_info()?;","handlingStrategy":"type-guard","validationCode":"if config.read().agent.is_none() { /* handle missing agent */ }","typeGuard":"fn has_agent(config: &GlobalConfig) -> bool { config.read().agent.is_some() }","tryCatchPattern":"match config.agent_info() { Ok(s) => println!(\"{s}\"), Err(e) if e.to_string() == \"No agent\" => eprintln!(\"Select an agent first\"), Err(e) => return Err(e) }","preventionTips":["Always run agent selection/init before agent subcommands","Check `agent list` is non-empty in scripts","Avoid calling agent_info before setup_model completes"],"tags":["agent","missing-state","cli"],"backgroundTag":"missing-required-config","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"}