{"record":{"id":"87dd4b673e2492b2","repo":"jdx/mise","slug":"environment-variable-key-not-found","errorCode":null,"errorMessage":"Environment variable {key} not found","messagePattern":"Environment variable (.+?) not found","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cli/set.rs","lineNumber":155,"sourceCode":"                mise_toml.remove_env(name)?;\n            }\n        }\n\n        if let Some(env_vars) = &self.env_vars\n            && env_vars.len() == 1\n            && env_vars[0].value.is_none()\n            && !self.prompt\n            && !self.stdin\n        {\n            let key = &env_vars[0].key;\n            // Use Config's centralized env loading which handles decryption\n            let full_config = Config::get().await?;\n            let env = full_config.env().await?;\n            match env.get(key) {\n                Some(value) => {\n                    miseprintln!(\"{value}\");\n                }\n                None => bail!(\"Environment variable {key} not found\"),\n            }\n            return Ok(());\n        }\n\n        if let Some(mut env_vars) = self.env_vars.take() {\n            // Prompt for values if requested\n            if self.prompt {\n                let theme = crate::ui::theme::get_theme();\n                for ev in &mut env_vars {\n                    if ev.value.is_none() {\n                        let prompt_msg = format!(\"Enter value for {}\", ev.key);\n                        let value = Input::new(&prompt_msg)\n                            .password(self.age_encrypt) // Mask input if encrypting\n                            .theme(&theme)\n                            .run()?;\n                        ev.value = Some(value);\n                    }\n                }","sourceCodeStart":137,"sourceCodeEnd":173,"githubUrl":"https://github.com/jdx/mise/blob/6f52dcdf99e282ef7a7db68c81301fa4618d0f79/src/cli/set.rs#L137-L173","documentation":"`mise set KEY` with a single bare key (no =VALUE, no --prompt, no --stdin) is the read form of the command: mise resolves the merged config environment through Config::env() — which includes decrypting age-encrypted entries — and prints the value. If the key is not defined in any mise config's [env], it bails 'Environment variable {key} not found'. It reads mise config env, not the process environment.","triggerScenarios":"Running `mise set FOO` when FOO is not defined in any loaded mise.toml [env] table (global, project, or local), or when FOO exists only as an OS/shell environment variable rather than a mise env entry.","commonSituations":"Typos in the key name; expecting `mise set KEY` to read the shell environment (use `echo $KEY` instead); the variable living in a different config file or config layer than the one currently trusted/loaded.","solutions":["List everything currently defined to confirm the exact key: `mise set` (no arguments)","Check all config layers involved: `mise config ls`, and query the specific file with `mise set --file <path> KEY`","If it should exist, define it first: `mise set FOO=bar`","If you meant the shell's environment variable, use `echo $FOO` — mise set only reads mise-managed env"],"exampleFix":"# before\nmise set DATABASE_URL   # Environment variable DATABASE_URL not found\n\n# after\nmise set                  # list keys to confirm spelling\nmise set --file mise.local.toml DATABASE_URL   # or query the file that defines it","handlingStrategy":"validation","validationCode":"# confirm the key exists in mise's env before reading it\nkey=FOO\nif mise set 2>/dev/null | awk 'NR>3 {print $1}' | grep -qx \"$key\"; then\n  val=$(mise set \"$key\")\nelse\n  echo \"$key not defined in mise config env\" >&2\nfi","typeGuard":"mise_env_has() { mise set 2>/dev/null | awk '{print $1}' | grep -qx \"$1\"; }","tryCatchPattern":"Check `mise set KEY` exit code and stderr; 'not found' means the key is absent from mise config env — fall back to a default or fail with a clear message rather than retrying.","preventionTips":["Use `mise set` (no args) to inventory available keys before scripting reads","Remember this reads mise config env, not process env — use $VAR for the latter","Keep env keys in one known config layer to make lookups predictable"],"tags":["env","config","cli","missing-env-var","mise"],"backgroundTag":"missing-env-var","analyzedSha":"6f52dcdf99e282ef7a7db68c81301fa4618d0f79","analyzedAt":"2026-08-22T10:14:23.840Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}