denisidoro/navi · error
{name} not set
Error message
{name} not set What it means
`env_var::must_get(name)` reads an environment variable and panics with "{name} not set" if it is missing. It is used for variables navi considers mandatory (e.g. config/feature selectors), so absence is treated as a fatal configuration error rather than a recoverable one.
Source
Thrown at src/env_var.rs:34
pub const FZF_OVERRIDES_VAR: &str = "NAVI_FZF_OVERRIDES_VAR";
pub const FINDER: &str = "NAVI_FINDER";
pub const CONFIG: &str = "NAVI_CONFIG";
pub const CONFIG_YAML: &str = "NAVI_CONFIG_YAML";
pub fn parse<T: FromStr>(varname: &str) -> Option<T> {
if let Ok(x) = env::var(varname) {
x.parse::<T>().ok()
} else {
None
}
}
pub fn must_get(name: &str) -> String {
if let Ok(v) = env::var(name) {
v
} else {
panic!("{name} not set")
}
}
pub fn escape(name: &str) -> String {
name.replace('-', "_")
}
View on GitHub (pinned to f7330b9ad5)
Solutions
- Export the required variable before running: `export NAVI_VAR=value`
- Set it inline for one run: `NAVI_VAR=value navi ...`
- Check for name mismatches — navi accepts dash or underscore in some lookups via `env_var::escape`, but the raw name must match exactly for must_get
- Add the export to your shell profile (~/.bashrc, ~/.zshrc) so it persists
Example fix
// before (fails) $ navi some-subcommand // thread 'main' panicked at 'NAVI_PATH not set' // after $ export NAVI_PATH="$HOME/.navi" $ navi some-subcommand
Defensive patterns
Strategy: validation
Validate before calling
fn require_env(name: &str) -> std::io::Result<String> {
std::env::var(name).map_err(|_| {
std::io::Error::new(std::io::ErrorKind::NotFound, format!("{} not set", name))
})
}
// call sites: require_env("NAVI_PATH")? before spawning navi Type guard
fn env_set(name: &str) -> Option<String> {
std::env::var(name).ok().filter(|v| !v.is_empty())
} Try / catch
// must_get panics; use catch_unwind or check first
if std::env::var_os(name).is_some() {
let v = navi::env_var::must_get(name);
} else {
eprintln!("{} not set", name);
std::process::exit(1);
} Prevention
- Export required variables in shell profiles and CI setup steps
- Double-check exact variable names (watch dash vs underscore)
- Set variables inline when running one-off commands
- Avoid relying on interactive-only exports in cron/systemd contexts
When it happens
Trigger: Calling `must_get("SOME_VAR")` (directly or via navi internals) when `std::env::var(name)` returns Err — i.e. the variable is absent from the process environment (empty-string values are OK and returned).
Common situations: Running navi without exporting a required variable, typos in variable names (e.g. NAVI_PATH vs NAVI_PATHS), CI environments that don't inherit your shell exports, or running under systemd/cron where the interactive shell profile isn't loaded.
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
- Could not open file in external editor
- Invalid link
- `{}` has no parent
- No files found
- No variables received from finder
AI-assisted analysis of denisidoro/navi@f7330b9ad5 (2026-09-03).
Data as JSON: /api/errors/7592a6a50fed54ea.
Report an issue: GitHub.