sigoden/aichat · error · anyhow::Error

Editor not found. Please add the `editor` configuration or…

Error message

Editor not found. Please add the `editor` configuration or set the $EDITOR or $VISUAL environment variable.

What it means

In src/config/mod.rs, editor resolution picks the configured `editor` value or falls back through environment variables ($EDITOR/$VISUAL) and well-known defaults (e.g. nano/vi), verifying each with `which::which`. If none resolves to an installed executable, the library throws this descriptive error.

Solutions

  1. Install an editor that exists on PATH (e.g. `apt install nano`).
  2. Set the `editor` field in the config to an installed executable.
  3. Export `EDITOR=/usr/bin/vim` (or $VISUAL) in your shell profile.
  4. Verify with `which $EDITOR` that the referenced binary resolves.

Example fix

// before
Error: Editor not found. ...

// after
export EDITOR=vim  # or add to config: editor = "vim"
Defensive patterns

Strategy: validation

Validate before calling

// Shell guard before invoking editor-dependent commands
command -v "${EDITOR:-nano}" >/dev/null 2>&1 || export EDITOR=$(command -v vi || command -v nano)

Try / catch

// Rust
match open_editor().await {
    Err(e) if e.to_string().starts_with("Editor not found") => {
    eprintln!("Install nano/vim or set $EDITOR");
    }
    other => other?,
}

Prevention

When it happens

Trigger: A feature that opens an editor (e.g. editing prompts/roles in the REPL) runs while: no `editor` config is set, $EDITOR and $VISUAL are unset or point to non-existent binaries, and no default editor (nano/vi) is on PATH.

Common situations: Minimal Docker/CI images with no editors installed; Windows without nano/vi and no $EDITOR set; $EDITOR pointing at an uninstalled program.

Understand the failure class

Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of sigoden/aichat@82976d349a (2026-09-09). Data as JSON: /api/errors/b8daf5cb7bcc4d67. Report an issue: GitHub.

Appendix: source

Thrown at src/config/mod.rs:1735

            Some(functions)
        }
    }

    pub fn editor(&self) -> Result<String> {
        EDITOR.get_or_init(move || {
            let editor = self.editor.clone()
                .or_else(|| env::var("VISUAL").ok().or_else(|| env::var("EDITOR").ok()))
                .unwrap_or_else(|| {
                    if cfg!(windows) {
                        "notepad".to_string()
                    } else {
                        "nano".to_string()
                    }
                });
            which::which(&editor).ok().map(|_| editor)
        })
        .clone()
        .ok_or_else(|| anyhow!("Editor not found. Please add the `editor` configuration or set the $EDITOR or $VISUAL environment variable."))
    }

    pub fn repl_complete(
        &self,
        cmd: &str,
        args: &[&str],
        _line: &str,
    ) -> Vec<(String, Option<String>)> {
        let mut values: Vec<(String, Option<String>)> = vec![];
        let filter = args.last().unwrap_or(&"");
        if args.len() == 1 {
            values = match cmd {
                ".role" => map_completion_values(Self::list_roles(true)),
                ".model" => list_models(self, ModelType::Chat)
                    .into_iter()
                    .map(|v| (v.id(), Some(v.description())))
                    .collect(),
                ".session" => {

View on GitHub (pinned to 82976d349a)