gitui-org/gitui · error · anyhow::Error
editor env variable found empty: {}
Error message
editor env variable found empty: {} What it means
gitui picks the external editor from a chain of environment options (GIT_EDITOR-class, then EDITOR, then VISUAL) and falls back to vi only when none are SET. If a variable is set but to an empty string, env::var returns Ok(""), the fallback never engages, and the peekable char iterator over the value is empty - .peek() yields None and this error names the offending variables (joined with ' or ').
Source
Thrown at src/popups/externaleditor.rs:89
let editor = env::var(environment_options[0])
.ok()
.or_else(|| {
get_config_string(repo, "core.editor").ok()?
})
.or_else(|| env::var(environment_options[1]).ok())
.or_else(|| env::var(environment_options[2]).ok())
.unwrap_or_else(|| String::from("vi"));
// TODO: proper handling arguments containing whitespaces
// This does not do the right thing if the input is `editor --something "with spaces"`
// deal with "editor name with spaces" p1 p2 p3
// and with "editor_no_spaces" p1 p2 p3
// does not address spaces in pn
let mut echars = editor.chars().peekable();
let first_char = *echars.peek().ok_or_else(|| {
anyhow!(
"editor env variable found empty: {}",
environment_options.join(" or ")
)
})?;
let command: String = if first_char == '\"' {
echars
.by_ref()
.skip(1)
.take_while(|c| *c != '\"')
.collect()
} else {
echars.by_ref().take_while(|c| *c != ' ').collect()
};
let remainder_str = echars.collect::<String>();
let remainder = remainder_str.split_whitespace();
let mut args: Vec<&OsStr> =View on GitHub (pinned to 2fa693cb6e)
Solutions
- Unset the variable (unset EDITOR VISUAL) so gitui's vi fallback engages, or set it to a real editor (export EDITOR=nvim).
- Audit shell rc files, Dockerfile ENV lines, and CI variable blocks for editor variables assigned empty strings.
- If 'no editor' is intentional for your workflow, remap gitui's edit keys in key_config.ron instead of blanking EDITOR.
Example fix
# Dockerfile
# before
ENV EDITOR=""
# after: drop the line entirely, or
ENV EDITOR=vim
// Rust callers: filter empties so fallbacks work
// before
let editor = env::var("EDITOR").ok().unwrap_or_else(|| "vi".into());
// after
let editor = env::var("EDITOR").ok().filter(|e| !e.is_empty())
.unwrap_or_else(|| "vi".into()); Defensive patterns
Strategy: validation
Validate before calling
# shell: make the vi fallback reachable when 'set but empty'
[ "${EDITOR:-}" ] || unset EDITOR
[ "${VISUAL:-}" ] || unset VISUAL
// Rust: filter empties when reading env vars with fallbacks
env::var("EDITOR").ok().filter(|v| !v.is_empty())
.or_else(|| env::var("VISUAL").ok().filter(|v| !v.is_empty()))
.unwrap_or_else(|| "vi".into()) Prevention
- Never export EDITOR/VISUAL as empty strings - unset them instead.
- Avoid ENV EDITOR= in Dockerfiles unless a real binary follows the equals sign.
- When reading env vars with fallbacks, always .filter(|v| !v.is_empty()).
When it happens
Trigger: export EDITOR="" or VISUAL="" surviving into gitui's environment; container images that define EDITOR as empty to 'disable editors'; a shell rc exporting ${SOME_UNSET_VAR}, which expands to an empty string.
Common situations: Hardened no-editor container policies; miswritten dotfiles; variables inherited empty from a parent process or CI template.
Related errors
AI-assisted analysis of gitui-org/gitui@2fa693cb6e (2026-08-16).
Data as JSON: /api/errors/be06cb8ecf1f9c8c.
Report an issue: GitHub.