{"record":{"id":"b8daf5cb7bcc4d67","repo":"sigoden/aichat","slug":"editor-not-found-please-add-the-editor-configur","errorCode":null,"errorMessage":"Editor not found. Please add the `editor` configuration or set the $EDITOR or $VISUAL environment variable.","messagePattern":"Editor not found\\. Please add the `editor` configuration or set the \\$EDITOR or \\$VISUAL environment variable\\.","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/config/mod.rs","lineNumber":1735,"sourceCode":"            Some(functions)\n        }\n    }\n\n    pub fn editor(&self) -> Result<String> {\n        EDITOR.get_or_init(move || {\n            let editor = self.editor.clone()\n                .or_else(|| env::var(\"VISUAL\").ok().or_else(|| env::var(\"EDITOR\").ok()))\n                .unwrap_or_else(|| {\n                    if cfg!(windows) {\n                        \"notepad\".to_string()\n                    } else {\n                        \"nano\".to_string()\n                    }\n                });\n            which::which(&editor).ok().map(|_| editor)\n        })\n        .clone()\n        .ok_or_else(|| anyhow!(\"Editor not found. Please add the `editor` configuration or set the $EDITOR or $VISUAL environment variable.\"))\n    }\n\n    pub fn repl_complete(\n        &self,\n        cmd: &str,\n        args: &[&str],\n        _line: &str,\n    ) -> Vec<(String, Option<String>)> {\n        let mut values: Vec<(String, Option<String>)> = vec![];\n        let filter = args.last().unwrap_or(&\"\");\n        if args.len() == 1 {\n            values = match cmd {\n                \".role\" => map_completion_values(Self::list_roles(true)),\n                \".model\" => list_models(self, ModelType::Chat)\n                    .into_iter()\n                    .map(|v| (v.id(), Some(v.description())))\n                    .collect(),\n                \".session\" => {","sourceCodeStart":1717,"sourceCodeEnd":1753,"githubUrl":"https://github.com/sigoden/aichat/blob/82976d349ad97ac9aae0655ad631dace5e2a6385/src/config/mod.rs#L1717-L1753","documentation":"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.","triggerScenarios":"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.","commonSituations":"Minimal Docker/CI images with no editors installed; Windows without nano/vi and no $EDITOR set; $EDITOR pointing at an uninstalled program.","solutions":["Install an editor that exists on PATH (e.g. `apt install nano`).","Set the `editor` field in the config to an installed executable.","Export `EDITOR=/usr/bin/vim` (or $VISUAL) in your shell profile.","Verify with `which $EDITOR` that the referenced binary resolves."],"exampleFix":"// before\nError: Editor not found. ...\n\n// after\nexport EDITOR=vim  # or add to config: editor = \"vim\"","handlingStrategy":"validation","validationCode":"// Shell guard before invoking editor-dependent commands\ncommand -v \"${EDITOR:-nano}\" >/dev/null 2>&1 || export EDITOR=$(command -v vi || command -v nano)","typeGuard":null,"tryCatchPattern":"// Rust\nmatch open_editor().await {\n    Err(e) if e.to_string().starts_with(\"Editor not found\") => {\n    eprintln!(\"Install nano/vim or set $EDITOR\");\n    }\n    other => other?,\n}","preventionTips":["Install at least one editor (nano or vim) in minimal environments.","Set $EDITOR in shell profiles and Dockerfiles.","Set the `editor` config field for portable setups.","Verify with `which $EDITOR` after changes."],"tags":["editor","env","config","cli"],"backgroundTag":"missing-env-var","analyzedSha":"82976d349ad97ac9aae0655ad631dace5e2a6385","analyzedAt":"2026-09-09T18:33:06.139Z","contentChangedAt":"2026-09-09T18:33:06.139Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}