nikivdev/code · error

editor exited with status {}

Error message

editor exited with status {}

What it means

Thrown after launching an external editor (from $EDITOR/$VISUAL or a default) to edit a notes file: the child process ran but returned a non-zero exit status. The error wraps the raw `status` so the developer sees the exit code. It means the editor itself failed, not that the file could not be opened (that produces the 'failed to open editor' context error instead).

Source

Thrown at src/ai.rs:15134

    // Create the file if it doesn't exist
    if !note_file.exists() {
        let template = format!(
            "# Session: {}\n\nSession ID: {}\n\n## Notes\n\n",
            session,
            &session_id[..8.min(session_id.len())]
        );
        fs::write(&note_file, template)?;
    }

    // Open in $EDITOR
    let editor = std::env::var("EDITOR").unwrap_or_else(|_| "vim".to_string());
    let status = Command::new(&editor)
        .arg(&note_file)
        .status()
        .with_context(|| format!("failed to open editor: {}", editor))?;

    if !status.success() {
        bail!("editor exited with status {}", status);
    }

    Ok(())
}

/// Remove a saved session from tracking.
fn remove_session(session: &str) -> Result<()> {
    let mut index = load_index()?;

    if index.sessions.remove(session).is_some() {
        save_index(&index)?;
        println!("Removed session '{}'", session);

        // Also remove notes if they exist
        let notes_dir = get_notes_dir()?;
        let note_file = notes_dir.join(format!("{}.md", session));
        if note_file.exists() {
            fs::remove_file(&note_file)?;

View on GitHub (pinned to a747e741ae)

Solutions

  1. Re-run the command and save/exit the editor normally with exit code 0
  2. Check your $EDITOR/$VISUAL value and test it directly on the notes file to reproduce the non-zero exit
  3. Fix editor config errors (vimrc, plugins) that cause non-zero exits
  4. Ensure the disk has space and the editor can write the file

Example fix

// before
EDITOR="vim -u brokenrc" f ai notes edit
// after
EDITOR=vim f ai notes edit   # or fix the editor config so it exits 0
Defensive patterns

Strategy: try-catch

Validate before calling

# shell: preflight the editor before invoking the command
command -v "${EDITOR%% *}" >/dev/null || { echo "EDITOR '$EDITOR' not found"; exit 1; }
: > /tmp/_editortest && "$EDITOR" /tmp/_editortest </dev/null >/dev/null 2>&1 || echo "warning: $EDITOR exits non-zero"

Try / catch

// catch and surface the editor exit code distinctly
match edit_notes(path) {
    Err(e) if e.to_string().starts_with("editor exited with status") => {
        eprintln!("{} — fix $EDITOR or save and quit with :wq", e);
        std::process::exit(1);
    }
    Err(e) => return Err(e),
    Ok(()) => Ok(()),
}

Prevention

When it happens

Trigger: The notes-edit command spawns `Command::new(editor).arg(note_file).status()`, the editor binary launches but exits non-zero (user aborts in vim/:q!, editor writes fail, editor crashes, bad editor config).

Common situations: $EDITOR set to a broken wrapper script; vim/emacs exiting non-zero due to .vimrc errors; disk-full preventing the editor from saving; user pressing Ctrl-C inside the editor; headless environment launching a TUI editor that fails.

Related errors


AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01). Data as JSON: /api/errors/db8325df76b6b936. Report an issue: GitHub.