{"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":305,"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":287,"sourceCodeEnd":323,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/cli/set.rs#L287-L323","documentation":"`mise set get` (mise set --get / `mise set` with a key filter) looks up each requested key in the environment map computed from all config sources (`env_with_sources`), which already includes decrypted values. If a requested key is not present in any active config's [env] directives, mise aborts with this error instead of printing anything. It is a user-facing lookup failure indicating the variable simply is not defined in the current environment context.","triggerScenarios":"Running `mise set <key>` (get path) where `config.env_with_sources()` returns no entry for the requested key — e.g. the key is defined in a different mise environment/directory, was removed from mise.toml, or was never set.","commonSituations":"Typo in the variable name; variable defined only in a project-level mise.toml while running from another directory; variable removed by a teammate's config change; expecting a shell-exported variable to be managed by mise when it is not in any [env] block.","solutions":["Run `mise env` to list all environment variables mise actually manages and confirm the exact key name.","Add the key to an [env] block in the appropriate mise.toml (or run `mise set KEY=value` to write it).","Check you are in the project directory (or use --cd) so the config file defining the variable is loaded."],"exampleFix":"// before: key not in any [env]\nmise set API_URL\n// error: Environment variable API_URL not found\n\n// after: define it first, then get\n[env]\nAPI_URL = \"https://api.example.com\"\n$ mise set API_URL","handlingStrategy":"validation","validationCode":"if mise env | grep -qx 'API_URL=.*'; then mise set API_URL; else echo 'API_URL not managed by mise' >&2; fi","typeGuard":null,"tryCatchPattern":"if ! value=$(mise set API_URL 2>/dev/null); then value=\"${API_URL_DEFAULT:-}\"; fi","preventionTips":["Keep a canonical [env] block in mise.toml and reference keys from it","Run `mise env` before scripting against managed variables","Use mise.toml in the working directory (or --cd) so configs load"],"tags":["cli","environment","env-vars"],"backgroundTag":"missing-env-var","analyzedSha":"533346cc374382b41ec5ff70536252b2e96e725c","analyzedAt":"2026-09-17T13:35:38.149Z","contentChangedAt":"2026-09-17T13:35:38.149Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}