{"record":{"id":"b88fce1e283a6272","repo":"sigoden/aichat","slug":"cannot-perform-this-operation-because-you-are-in-a-b88fce","errorCode":null,"errorMessage":"Cannot perform this operation because you are in a macro","messagePattern":"Cannot perform this operation because you are in a macro","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/repl/mod.rs","lineNumber":520,"sourceCode":"                None => {\n                    let banner = config.read().agent_banner()?;\n                    config.read().print_markdown(&banner)?;\n                }\n            },\n            \".save\" => match split_first_arg(args) {\n                Some((\"role\", name)) => {\n                    config.write().save_role(name)?;\n                }\n                Some((\"session\", name)) => {\n                    config.write().save_session(name)?;\n                }\n                _ => {\n                    println!(r#\"Usage: .save <role|session> [name]\"#)\n                }\n            },\n            \".edit\" => {\n                if config.read().macro_flag {\n                    bail!(\"Cannot perform this operation because you are in a macro\")\n                }\n                match args {\n                    Some(\"config\") => {\n                        config.read().edit_config()?;\n                    }\n                    Some(\"role\") => {\n                        config.write().edit_role()?;\n                    }\n                    Some(\"session\") => {\n                        config.write().edit_session()?;\n                    }\n                    Some(\"rag-docs\") => {\n                        Config::edit_rag_docs(config, abort_signal.clone()).await?;\n                    }\n                    Some(\"agent-config\") => {\n                        config.write().edit_agent_config()?;\n                    }\n                    _ => {","sourceCodeStart":502,"sourceCodeEnd":538,"githubUrl":"https://github.com/sigoden/aichat/blob/82976d349ad97ac9aae0655ad631dace5e2a6385/src/repl/mod.rs#L502-L538","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// macro file — before\n.edit config\n.model gpt-4\n// after: run .edit interactively, keep macro to non-interactive commands\n.model gpt-4","handlingStrategy":"try-catch","validationCode":"// guard macros against interactive commands\nconst MACRO_FORBIDDEN: &[&str] = &[\".edit\"];\nif MACRO_FORBIDDEN.iter().any(|c| line.starts_with(c)) {\n    eprintln!(\"{} cannot run inside a macro\", line);\n}","typeGuard":null,"tryCatchPattern":"match run_repl_command(...).await {\n    Err(e) if e.to_string().contains(\"you are in a macro\") => {\n        eprintln!(\"Run .edit outside of macros\");\n    }\n    other => other?,\n}","preventionTips":["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"],"tags":["repl","macro","unsupported-operation"],"backgroundTag":"unsupported-operation","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"}