{"record":{"id":"a788564ff354bb3c","repo":"sigoden/aichat","slug":"cannot-perform-this-operation-because-you-are-in-a","errorCode":null,"errorMessage":"Cannot perform this operation because you are in a non-empty session","messagePattern":"Cannot perform this operation because you are in a non-empty session","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/config/mod.rs","lineNumber":971,"sourceCode":"        let ans = Confirm::new(\"Create a new role?\")\n            .with_default(true)\n            .prompt()?;\n        if ans {\n            self.upsert_role(name)?;\n        } else {\n            bail!(\"No role\");\n        }\n        Ok(())\n    }\n\n    pub fn edit_role(&mut self) -> Result<()> {\n        let role_name;\n        if let Some(session) = self.session.as_ref() {\n            if let Some(name) = session.role_name().map(|v| v.to_string()) {\n                if session.is_empty() {\n                    role_name = Some(name);\n                } else {\n                    bail!(\"Cannot perform this operation because you are in a non-empty session\")\n                }\n            } else {\n                bail!(\"No role\")\n            }\n        } else {\n            role_name = self.role.as_ref().map(|v| v.name().to_string());\n        }\n        let name = role_name.ok_or_else(|| anyhow!(\"No role\"))?;\n        self.upsert_role(&name)?;\n        self.use_role(&name)\n    }\n\n    pub fn upsert_role(&mut self, name: &str) -> Result<()> {\n        let role_path = Self::role_file(name);\n        ensure_parent_exists(&role_path)?;\n        let editor = self.editor()?;\n        edit_file(&editor, &role_path)?;\n        if self.working_mode.is_repl() {","sourceCodeStart":953,"sourceCodeEnd":989,"githubUrl":"https://github.com/sigoden/aichat/blob/82976d349ad97ac9aae0655ad631dace5e2a6385/src/config/mod.rs#L953-L989","documentation":"Guard in edit_role(): editing the current session's role is only allowed while the session is still empty; if the session already has messages, editing would silently change the role for existing conversation state, so the operation is refused. The state at fault is a non-empty active session with an assigned role.","triggerScenarios":"Thrown at src/config/mod.rs:971 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Start a new session before editing the role","Clear or abandon the current session's messages first","Edit the role file directly outside the active session"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}