atuinsh/atuin · error

failed to open editor

Error message

failed to open editor

What it means

Atuin's script editor launcher spawns the configured editor via `std::process::Command` and checks the resulting exit status. When the editor process runs but exits with a non-zero status, `bail!("failed to open editor")` aborts the operation. This typically means the editor itself failed (bad terminal, unsupported flags, editor crashed) rather than atuin being unable to find the editor binary.

Source

Thrown at crates/atuin/src/command/client/scripts.rs:144

        // Create a temporary file
        let temp_file = NamedTempFile::new()?;
        let path = temp_file.into_temp_path();

        // Write initial content to the temp file if provided
        if let Some(content) = initial_content {
            std::fs::write(&path, content)?;
        }

        // Open the file in the user's preferred editor
        let editor_str = std::env::var("EDITOR").unwrap_or_else(|_| "vi".to_string());

        // Use shlex to safely split the string into shell-like parts.
        let parts = shlex::split(&editor_str).ok_or_eyre("Failed to parse editor command")?;
        let (command, args) = parts.split_first().ok_or_eyre("No editor command found")?;

        let status = std::process::Command::new(command).args(args).arg(&path).status()?;
        if !status.success() {
            bail!("failed to open editor");
        }

        // Read back the edited content
        let content = std::fs::read_to_string(&path)?;
        path.close()?;

        Ok(content)
    }

    // Helper function to execute a script and manage stdin/stdout/stderr
    async fn execute_script(script_content: String, shebang: String) -> Result<i32> {
        let mut session = execute_script_interactive(script_content, shebang)
            .await
            .expect("failed to execute script");

        // Create a channel to signal when the process exits
        let (exit_tx, mut exit_rx) = tokio::sync::oneshot::channel();

View on GitHub (pinned to c0c717ab04)

Solutions

  1. Verify $EDITOR/$VISUAL works: run `"$EDITOR" <file>` manually on a test file and check its exit code.
  2. Set a known-good terminal editor: `export EDITOR=vim` (or nano/emacs) in your shell profile.
  3. If using a GUI editor, add the wait flag it requires (e.g. `code --wait`) so the process exits correctly after editing.
  4. Use `--no-edit` on `atuin scripts new` to skip the editor entirely and pipe/author content another way.
  5. Run atuin in an interactive terminal so the editor gets a usable TTY.

Example fix

// before
export EDITOR="code"
// after
export EDITOR="code --wait"  # or a terminal editor: export EDITOR=vim
Defensive patterns

Strategy: validation

Validate before calling

// shell
if [ -n "$EDITOR" ] && ! command -v "${EDITOR%% *}" >/dev/null 2>&1; then
  echo "EDITOR '$EDITOR' not available" >&2
fi
# also test: "$EDITOR" /tmp/probe.txt && echo editor-ok || echo editor-fails

Try / catch

// in a wrapper script
if ! atuin scripts new "my cmd"; then
  echo "editor failed; retry with --no-edit" >&2
  atuin scripts new --no-edit "my cmd"
fi

Prevention

When it happens

Trigger: Calling any atuin scripts subcommand that opens an editor (e.g. `atuin scripts new` without `--no-edit`, `atuin scripts edit`) where `$EDITOR`/configured editor launches but exits non-zero.

Common situations: EDITOR set to a GUI editor that fails without a display (e.g. `code --wait` without VS Code running properly), editor opening in a non-interactive/captured-stdio context, editor crashing on the temp file, or the user quitting the editor with an error exit code.

Understand the failure class

Background: "git command failed": what it means when a tool shells out to git and git exits non-zero — this error's family across 21 libraries.

Related errors


AI-assisted analysis of atuinsh/atuin@c0c717ab04 (2026-09-12). Data as JSON: /api/errors/0a5ce3448f7c54bf. Report an issue: GitHub.