denisidoro/navi · critical

Could not open file in external editor

Error message

Could not open file in external editor

What it means

Raised in `act` in src/commands/core/actor.rs (src/commands/core/actor.rs:224) via `.expect("Could not open file in external editor")` when `edit::edit_file` fails to spawn or run the external editor on the selected file. The file index was valid, but launching the editor errored.

Source

Thrown at src/commands/core/actor.rs:224

pub fn act(
    extractions: Result<(&str, Item)>,
    files: Vec<String>,
    variables: Option<VariableMap>,
) -> Result<()> {
    let (
        key,
        Item {
            tags,
            comment,
            snippet,
            file_index,
            ..
        },
    ) = extractions.unwrap();

    if key == "ctrl-o" {
        edit::edit_file(Path::new(&files[file_index.expect("No files found")]))
            .expect("Could not open file in external editor");
        return Ok(());
    }

    env_var::set(env_var::PREVIEW_INITIAL_SNIPPET, &snippet);
    env_var::set(env_var::PREVIEW_TAGS, &tags);
    env_var::set(env_var::PREVIEW_COMMENT, comment);

    let interpolated_snippet = {
        let mut s = replace_variables_from_snippet(
            &snippet,
            &tags,
            variables.expect("No variables received from finder"),
        )
        .context("Failed to replace variables from snippet")?;
        s = with_absolute_path(s);
        s = deser::with_new_lines(s);
        s
    };

View on GitHub (pinned to f7330b9ad5)

Solutions

  1. Set `$EDITOR` (or `$VISUAL`) to a working editor, e.g. `export EDITOR=vim`
  2. Verify the editor binary exists on PATH (`which $EDITOR`)
  3. Check the target file exists and is writable
  4. Run in an environment where the configured editor can actually start (TTY available)

Example fix

// before (shell)
./tool  # EDITOR unset -> panic on ctrl-o
// after (shell)
export EDITOR=vim
./tool
Defensive patterns

Strategy: validation

Validate before calling

let editor_ok = std::env::var("EDITOR")
    .or_else(|_| std::env::var("VISUAL"))
    .map(|e| which::which(&e).is_ok())
    .unwrap_or(false);
if !editor_ok { eprintln!("Set EDITOR to a working editor before using ctrl-o"); }

Try / catch

let status = child.wait()?;
if !status.success() && stderr.contains("Could not open file in external editor") {
    eprintln!("Check $EDITOR/$VISUAL point to an installed, runnable editor.");
}

Prevention

When it happens

Trigger: Pressing ctrl-o on a valid file selection when the external editor cannot be launched — `$EDITOR`/`$VISUAL` unset or pointing at a nonexistent binary, the editor exits non-zero, or the file path is inaccessible.

Common situations: Minimal Docker/CI environments with no editor configured; EDITOR set to a GUI app unavailable in the current session; typo in the EDITOR variable; read-only or deleted target file.

Related errors


AI-assisted analysis of denisidoro/navi@f7330b9ad5 (2026-09-03). Data as JSON: /api/errors/3c3f4592221859e3. Report an issue: GitHub.