sigoden/aichat · error

Cannot perform this operation because you are in a…

Error message

Cannot perform this operation because you are in a non-empty session

What it means

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.

Solutions

  1. Start a new session before editing the role
  2. Clear or abandon the current session's messages first
  3. Edit the role file directly outside the active session
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at src/config/mod.rs:971 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of sigoden/aichat@82976d349a (2026-09-09). Data as JSON: /api/errors/a788564ff354bb3c. Report an issue: GitHub.

Appendix: source

Thrown at src/config/mod.rs:971

        let ans = Confirm::new("Create a new role?")
            .with_default(true)
            .prompt()?;
        if ans {
            self.upsert_role(name)?;
        } else {
            bail!("No role");
        }
        Ok(())
    }

    pub fn edit_role(&mut self) -> Result<()> {
        let role_name;
        if let Some(session) = self.session.as_ref() {
            if let Some(name) = session.role_name().map(|v| v.to_string()) {
                if session.is_empty() {
                    role_name = Some(name);
                } else {
                    bail!("Cannot perform this operation because you are in a non-empty session")
                }
            } else {
                bail!("No role")
            }
        } else {
            role_name = self.role.as_ref().map(|v| v.name().to_string());
        }
        let name = role_name.ok_or_else(|| anyhow!("No role"))?;
        self.upsert_role(&name)?;
        self.use_role(&name)
    }

    pub fn upsert_role(&mut self, name: &str) -> Result<()> {
        let role_path = Self::role_file(name);
        ensure_parent_exists(&role_path)?;
        let editor = self.editor()?;
        edit_file(&editor, &role_path)?;
        if self.working_mode.is_repl() {

View on GitHub (pinned to 82976d349a)