{"record":{"id":"5f58a6fbd47967e1","repo":"jdx/mise","slug":"environment-variable-not-found","errorCode":null,"errorMessage":"Environment variable {} not found","messagePattern":"Environment variable (.+?) not found","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cli/set.rs","lineNumber":297,"sourceCode":"                    None // Fall back to global config if no local config exists\n                }\n            }\n        } else {\n            None\n        };\n\n        let filter = self.env_vars.unwrap();\n\n        // Handle global config case first\n        if config_path.is_none() {\n            let config = Config::get().await?;\n            let env_with_sources = config.env_with_sources().await?;\n            // env_with_sources already contains decrypted values\n            for eva in filter {\n                if let Some((value, _source)) = env_with_sources.get(&eva.key) {\n                    miseprintln!(\"{value}\");\n                } else {\n                    bail!(\"Environment variable {} not found\", eva.key);\n                }\n            }\n            return Ok(());\n        }\n\n        // Get the config to access directives directly\n        let config = MiseToml::from_file(&config_path.unwrap()).unwrap_or_default();\n\n        // For local configs, check directives directly\n        let env_entries = config.env_entries()?;\n        for eva in filter {\n            match env_entries.iter().find_map(|ev| match ev {\n                EnvDirective::Val(k, v, _) if k == &eva.key => Some((v.clone(), Some(ev))),\n                EnvDirective::Age {\n                    key: k, value: v, ..\n                } if k == &eva.key => Some((v.clone(), Some(ev))),\n                _ => None,\n            }) {","sourceCodeStart":279,"sourceCodeEnd":315,"githubUrl":"https://github.com/jdx/mise/blob/6f52dcdf99e282ef7a7db68c81301fa4618d0f79/src/cli/set.rs#L279-L315","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"# before\nmise set API_TOKEN DB_TOKEN   # Environment variable DB_TOKEN not found\n\n# after\nmise set                          # confirm which keys exist\nmise set API_TOKEN                # query only keys that are defined","handlingStrategy":"validation","validationCode":"# pre-flight each key against the merged env\nfor key in FOO BAR; do\n  mise set 2>/dev/null | awk '{print $1}' | grep -qx \"$key\" \\\n    || { echo \"$key missing from mise config env\" >&2; exit 2; }\ndone\nmise set FOO BAR","typeGuard":"mise_env_has() { mise set 2>/dev/null | awk '{print $1}' | grep -qx \"$1\"; }","tryCatchPattern":"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.","preventionTips":["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"],"tags":["env","config","missing-env-var","cli","mise"],"backgroundTag":"missing-env-var","analyzedSha":"6f52dcdf99e282ef7a7db68c81301fa4618d0f79","analyzedAt":"2026-08-22T10:14:23.840Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T20:17:18.057Z"}