sigoden/aichat · error
Cannot perform this operation because you are in a macro
Error message
Cannot perform this operation because you are in a macro
What it means
The `.edit` REPL command is disallowed inside macro execution: `config.read().macro_flag` is true while a macro is running, and editing files interactively mid-macro would be unsafe, so the command bails with this error.
Solutions
- Move the .edit command out of the macro and run it directly at the REPL prompt
- Remove the .edit line from your macro file
- Edit the config/role/session file manually with your own editor instead of .edit
Example fix
// macro file — before .edit config .model gpt-4 // after: run .edit interactively, keep macro to non-interactive commands .model gpt-4
Defensive patterns
Strategy: try-catch
Validate before calling
// guard macros against interactive commands
const MACRO_FORBIDDEN: &[&str] = &[".edit"];
if MACRO_FORBIDDEN.iter().any(|c| line.starts_with(c)) {
eprintln!("{} cannot run inside a macro", line);
} Try / catch
match run_repl_command(...).await {
Err(e) if e.to_string().contains("you are in a macro") => {
eprintln!("Run .edit outside of macros");
}
other => other?,
} Prevention
- Never put .edit lines in macro files
- Keep macros limited to non-interactive commands (.model, .save role, prompts)
- Review macro scripts for interactive-only commands before .source-ing them
When it happens
Trigger: Invoking `.edit` (e.g. `.edit config`, `.edit role`, `.edit session`) from within a macro (a file loaded via `.source` or a macro invocation) rather than typing it directly at the REPL prompt.
Common situations: A macro script contains an `.edit` line; copy-pasting a block of commands that includes `.edit` while a macro is active; nesting macros that call .edit.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- The model does not support network images
- Already in a session, please run '.exit session' first to…
- No session
- No macro
- No TTY for REPL
AI-assisted analysis of sigoden/aichat@82976d349a (2026-09-09).
Data as JSON: /api/errors/b88fce1e283a6272.
Report an issue: GitHub.
Appendix: source
Thrown at src/repl/mod.rs:520
None => {
let banner = config.read().agent_banner()?;
config.read().print_markdown(&banner)?;
}
},
".save" => match split_first_arg(args) {
Some(("role", name)) => {
config.write().save_role(name)?;
}
Some(("session", name)) => {
config.write().save_session(name)?;
}
_ => {
println!(r#"Usage: .save <role|session> [name]"#)
}
},
".edit" => {
if config.read().macro_flag {
bail!("Cannot perform this operation because you are in a macro")
}
match args {
Some("config") => {
config.read().edit_config()?;
}
Some("role") => {
config.write().edit_role()?;
}
Some("session") => {
config.write().edit_session()?;
}
Some("rag-docs") => {
Config::edit_rag_docs(config, abort_signal.clone()).await?;
}
Some("agent-config") => {
config.write().edit_agent_config()?;
}
_ => {View on GitHub (pinned to 82976d349a)