jdx/mise · error
Environment variable {} not found
Error message
Environment variable {} not found What it means
In the query path of `mise set KEY [KEY...]` with no --file, mise builds env_with_sources() from the fully merged, decrypted config environment and prints each requested key's value. The first key not present in that map bails 'Environment variable {key} not found'. Unlike the single-key fast path, this loop handles multiple keys and reports per-key misses against the merged view (values may come from any config layer).
Source
Thrown at src/cli/set.rs:297
None // Fall back to global config if no local config exists
}
}
} else {
None
};
let filter = self.env_vars.unwrap();
// Handle global config case first
if config_path.is_none() {
let config = Config::get().await?;
let env_with_sources = config.env_with_sources().await?;
// env_with_sources already contains decrypted values
for eva in filter {
if let Some((value, _source)) = env_with_sources.get(&eva.key) {
miseprintln!("{value}");
} else {
bail!("Environment variable {} not found", eva.key);
}
}
return Ok(());
}
// Get the config to access directives directly
let config = MiseToml::from_file(&config_path.unwrap()).unwrap_or_default();
// For local configs, check directives directly
let env_entries = config.env_entries()?;
for eva in filter {
match env_entries.iter().find_map(|ev| match ev {
EnvDirective::Val(k, v, _) if k == &eva.key => Some((v.clone(), Some(ev))),
EnvDirective::Age {
key: k, value: v, ..
} if k == &eva.key => Some((v.clone(), Some(ev))),
_ => None,
}) {View on GitHub (pinned to 6f52dcdf99)
Solutions
- List defined keys to verify spelling: `mise set`
- Check which config layers are loaded: `mise config ls`, `mise ls` — and make sure the defining file is trusted
- Define the missing key: `mise set FOO=bar`, or remove it from your query list
Example fix
# before mise set API_TOKEN DB_TOKEN # Environment variable DB_TOKEN not found # after mise set # confirm which keys exist mise set API_TOKEN # query only keys that are defined
Defensive patterns
Strategy: validation
Validate before calling
# pre-flight each key against the merged env
for key in FOO BAR; do
mise set 2>/dev/null | awk '{print $1}' | grep -qx "$key" \
|| { echo "$key missing from mise config env" >&2; exit 2; }
done
mise set FOO BAR Type guard
mise_env_has() { mise set 2>/dev/null | awk '{print $1}' | grep -qx "$1"; } Try / catch
Parse the failing key from 'Environment variable X not found' and either define it (`mise set X=v`), skip it, or fail fast with context — do not blind-retry.
Prevention
- Batch-query only keys you have verified exist via `mise set`
- Keep encrypted and plain env keys in trusted config layers
- Log which config files were loaded (`mise config ls`) in scripts that depend on env values
When it happens
Trigger: Running `mise set FOO BAR` where at least one of FOO/BAR is not defined in any loaded mise config's [env] (global + project + local merged); asking for a key that is only set as a process env var.
Common situations: Batch-querying several config vars in scripts and one is missing or misspelled; the key defined only in an untrusted/ignored config file; encrypted (age) key failing earlier decryption is a different error — this one means the key simply is not there.
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
- Environment variable {key} not found
- --stdin requires exactly one environment variable key
- --stdin reads the value from stdin; do not provide a value w
- Setting [{}] is not set
- Unknown setting: {}
AI-assisted analysis of jdx/mise@6f52dcdf99 (2026-08-22).
Data as JSON: /api/errors/5f58a6fbd47967e1.
Report an issue: GitHub.