{"record":{"id":"b6898bf7006fa83e","repo":"xai-org/grok-build","slug":"invalid-environment-variable-format-pair-env","errorCode":null,"errorMessage":"Invalid environment variable format: '{pair}'. Environment variables should be added as: -e KEY1=value1 -e KEY2=value2","messagePattern":"Invalid environment variable format: '(.+?)'\\. Environment variables should be added as: -e KEY1=value1 -e KEY2=value2","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codegen/xai-grok-pager/src/mcp_cmd.rs","lineNumber":442,"sourceCode":"        || !name\n            .chars()\n            .all(|c| c.is_ascii_alphanumeric() || c == '-' || c == '_')\n    {\n        bail!(\n            \"Invalid name '{name}'. Names can only contain letters, numbers, hyphens, and underscores.\"\n        );\n    }\n    Ok(())\n}\n\nfn parse_env_vars(pairs: &[String]) -> Result<HashMap<String, String>> {\n    let mut env = HashMap::new();\n    for pair in pairs {\n        match pair.split_once('=') {\n            Some((key, value)) if !key.is_empty() => {\n                env.insert(key.to_string(), value.to_string());\n            }\n            _ => bail!(\n                \"Invalid environment variable format: '{pair}'. Environment variables should be added as: -e KEY1=value1 -e KEY2=value2\"\n            ),\n        }\n    }\n    Ok(env)\n}\n\nfn parse_headers(headers: &[String]) -> Result<HashMap<String, String>> {\n    let mut parsed = HashMap::new();\n    for header in headers {\n        let Some((name, value)) = header.split_once(':') else {\n            bail!(\"Invalid header format: '{header}'. Expected format: 'Name: value'\");\n        };\n        let name = name.trim();\n        if name.is_empty() {\n            bail!(\"Invalid header: '{header}'. Header name cannot be empty.\");\n        }\n        parsed.insert(name.to_string(), value.trim().to_string());","sourceCodeStart":424,"sourceCodeEnd":460,"githubUrl":"https://github.com/xai-org/grok-build/blob/bc7f02eddd3d84085849dc19ed216f11c23b0571/crates/codegen/xai-grok-pager/src/mcp_cmd.rs#L424-L460","documentation":"`parse_env_vars` requires every -e value to be a KEY=value pair with a non-empty key. Any pair lacking an `=` or with an empty key is rejected with this message, which restates the correct per-flag syntax.","triggerScenarios":"`-e KEY` (no =value), `-e =value` (empty key), or an unquoted value containing spaces that split into multiple args like `-e KEY=hello world`.","commonSituations":"Shell splitting of unquoted values with spaces, assuming -e is greedy and accepts multiple pairs (`-e A=1 B=2`), passing bare variable names expecting the parent environment to be forwarded.","solutions":["Quote each pair: -e \"KEY=value with spaces\".","Use one -e flag per variable: -e A=1 -e B=2.","Ensure each pair contains '=' with a non-empty key before the equals sign."],"exampleFix":"// before\ngrok mcp add fs -e LOG_LEVEL -- npx server-fs\n// after\ngrok mcp add fs -e LOG_LEVEL=debug -- npx server-fs","handlingStrategy":"validation","validationCode":"for pair in env_pairs {\n    match pair.split_once('=') {\n        Some((k, _)) if !k.is_empty() => {}\n        _ => panic!(\"'{pair}' is not KEY=value; use one -e flag per variable\"),\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Quote values containing spaces.","One -e flag per variable, always with KEY=value.","Never pass bare variable names to -e."],"tags":["cli","mcp","environment-variables","parsing"],"backgroundTag":"invalid-env-var-format","analyzedSha":"bc7f02eddd3d84085849dc19ed216f11c23b0571","analyzedAt":"2026-08-31T04:59:42.031Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}