{"record":{"id":"0a5ce3448f7c54bf","repo":"atuinsh/atuin","slug":"failed-to-open-editor","errorCode":null,"errorMessage":"failed to open editor","messagePattern":"failed to open editor","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/atuin/src/command/client/scripts.rs","lineNumber":144,"sourceCode":"        // Create a temporary file\n        let temp_file = NamedTempFile::new()?;\n        let path = temp_file.into_temp_path();\n\n        // Write initial content to the temp file if provided\n        if let Some(content) = initial_content {\n            std::fs::write(&path, content)?;\n        }\n\n        // Open the file in the user's preferred editor\n        let editor_str = std::env::var(\"EDITOR\").unwrap_or_else(|_| \"vi\".to_string());\n\n        // Use shlex to safely split the string into shell-like parts.\n        let parts = shlex::split(&editor_str).ok_or_eyre(\"Failed to parse editor command\")?;\n        let (command, args) = parts.split_first().ok_or_eyre(\"No editor command found\")?;\n\n        let status = std::process::Command::new(command).args(args).arg(&path).status()?;\n        if !status.success() {\n            bail!(\"failed to open editor\");\n        }\n\n        // Read back the edited content\n        let content = std::fs::read_to_string(&path)?;\n        path.close()?;\n\n        Ok(content)\n    }\n\n    // Helper function to execute a script and manage stdin/stdout/stderr\n    async fn execute_script(script_content: String, shebang: String) -> Result<i32> {\n        let mut session = execute_script_interactive(script_content, shebang)\n            .await\n            .expect(\"failed to execute script\");\n\n        // Create a channel to signal when the process exits\n        let (exit_tx, mut exit_rx) = tokio::sync::oneshot::channel();\n","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/atuinsh/atuin/blob/900007c48045867e7f44b0f9bc55ad9dbe99ee0d/crates/atuin/src/command/client/scripts.rs#L126-L162","documentation":"`open_editor` spawns the configured editor as a child process to edit a temp script file. If the editor process exits with a non-zero status, the command assumes the edit failed and bails. Note: some editors (e.g. vim with `:cq`, or diff-conflicting tools) exit non-zero even after a successful edit.","triggerScenarios":"Editing a new/existing script (e.g. `atuin scripts new`) where the editor command configured via `$EDITOR`/settings exits non-zero after the user saves.","commonSituations":"Vim terminated with `:cq` or a killed buffer; editor crashed; `$EDITOR` set to a wrapper script returning non-zero; terminal issue interrupting the child.","solutions":["Re-run the command and exit the editor normally (e.g. `:wq` in vim, not `:cq`).","Check/change `$EDITOR` to a reliable editor: `export EDITOR=vim` (or nano/code --wait).","Verify the editor command runs standalone on the file to confirm the non-zero exit source."],"exampleFix":"# before\nexport EDITOR='code'   # returns immediately / non-zero without --wait\n\n# after\nexport EDITOR='code --wait'","handlingStrategy":"fallback","validationCode":"# verify the editor works and exits 0 before relying on it:\n$EDITOR /tmp/atuin-editor-check </dev/null >/dev/null 2>&1 \\\n  || echo \"warning: $EDITOR exits non-zero; set EDITOR to a stable editor\"","typeGuard":null,"tryCatchPattern":"if let Err(e) = open_editor(&path).await {\n    if e.to_string().contains(\"failed to open editor\") {\n        eprintln!(\"editor exited non-zero; re-run and quit the editor normally (e.g. :wq)\");\n    }\n    return Err(e);\n}","preventionTips":["Set EDITOR to an editor that exits 0 on normal saves (vim/nano; `code --wait`).","Never leave editors via `:cq` when scripting.","Test wrapper-editor scripts return 0 on success."],"tags":["editor","subprocess","exit-code"],"backgroundTag":"command-not-found","analyzedSha":"900007c48045867e7f44b0f9bc55ad9dbe99ee0d","analyzedAt":"2026-09-19T12:52:51.491Z","contentChangedAt":"2026-09-19T12:52:51.491Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}