{"record":{"id":"b0e15e3ca56f429d","repo":"Hmbown/CodeWhale","slug":"key-missing","errorCode":null,"errorMessage":"{key} missing","messagePattern":"(.+?) missing","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/hooks/executor.rs","lineNumber":4946,"sourceCode":"        assert_eq!(\n            without_code.get(\"DEEPSEEK_TOOL_SUCCESS\"),\n            Some(&\"false\".to_string())\n        );\n    }\n\n    #[test]\n    fn payload_env_vars_are_bounded() {\n        // Errors used to be the one unbounded field; a failed `exec_shell`\n        // could push its whole output into `DEEPSEEK_ERROR`.\n        let long = \"x\".repeat(20_000);\n        let env = HookContext::new()\n            .with_error(&long)\n            .with_message(&long)\n            .with_tool_result(&long, false, None)\n            .to_env_vars();\n\n        for key in [\"DEEPSEEK_ERROR\", \"DEEPSEEK_MESSAGE\", \"DEEPSEEK_TOOL_RESULT\"] {\n            let value = env.get(key).unwrap_or_else(|| panic!(\"{key} missing\"));\n            assert!(value.len() < 20_000, \"{key} was not truncated\");\n            assert!(value.ends_with(\"...[truncated]\"), \"{key} lost its marker\");\n        }\n    }\n\n    #[test]\n    fn truncate_env_value_respects_utf8_boundaries() {\n        // 4-byte characters straddling the cap must not panic or split.\n        let value = \"🐋\".repeat(100);\n        let truncated = super::truncate_env_value(&value, 10);\n        assert!(truncated.ends_with(\"...[truncated]\"));\n        let head = truncated.trim_end_matches(\"...[truncated]\");\n        assert!(head.chars().all(|c| c == '🐋'));\n        assert!(head.len() <= 12);\n    }\n\n    #[cfg(unix)]\n    #[test]","sourceCodeStart":4928,"sourceCodeEnd":4964,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/crates/tui/src/hooks/executor.rs#L4928-L4964","documentation":"This is a panic inside a TUI test verifying that AgentEnvVars.to_env_vars truncates oversized DEEPSEEK_* values and appends a `...[truncated]` marker. `panic!(\"{key} missing\")` fires when `env.get(key)` returns None — i.e. the env-var map built by to_env_vars lacked one of the expected DEEPSEEK_ERROR / DEEPSEEK_MESSAGE / DEEPSEEK_TOOL_RESULT keys, meaning a with_error/with_message/with_tool_result input was not propagated into the env map.","triggerScenarios":"Calling to_env_vars after with_error/with_message/with_tool_result and asserting on DEEPSEEK_* keys that were not emitted — typically after changing to_env_vars key names or dropping a field from the builder.","commonSituations":"Refactoring the env-var naming scheme (e.g. renaming DEEPSEEK_MESSAGE) or the builder so a setter no longer records its value; test data where the setter silently ignored the input.","solutions":["Check which DEEPSEEK_* keys to_env_vars actually emits (print/inspect the map) and compare against the test's key list.","Fix the key-name mismatch in either to_env_vars or the test.","Verify with_error/with_message/with_tool_result actually store their values in the builder state.","Re-run the test to confirm all three keys are present and truncated."],"exampleFix":"// before (executor.rs)\nlet value = env.get(\"DEEPSEEK_MSG\").unwrap_or_else(|| panic!(\"{key} missing\"));\n// after (key aligned with to_env_vars output)\nlet value = env.get(\"DEEPSEEK_MESSAGE\").unwrap_or_else(|| panic!(\"{key} missing\"));","handlingStrategy":"validation","validationCode":"let env = builder.to_env_vars();\nfor key in [\"DEEPSEEK_ERROR\", \"DEEPSEEK_MESSAGE\", \"DEEPSEEK_TOOL_RESULT\"] {\n    assert!(env.contains_key(key), \"{key} not emitted by to_env_vars\");\n}","typeGuard":"fn emitted(env: &HashMap<String, String>, key: &str) -> bool { env.contains_key(key) }","tryCatchPattern":"match env.get(key) {\n    Some(v) => assert!(v.ends_with(\"...[truncated]\")),\n    None => panic!(\"{key} missing from to_env_vars output\"),\n}","preventionTips":["Keep env-var key names in a single shared constant list used by both to_env_vars and tests","When renaming a DEEPSEEK_* key, update builder, emitter, and tests in one commit","Print the full env map in test failure output for faster diagnosis"],"tags":["rust","test","panic","env-vars","truncation"],"backgroundTag":"missing-env-var","analyzedSha":"433685b2024e7bc4c99e1e2e326bcad39b4d9d65","analyzedAt":"2026-09-15T12:24:24.634Z","contentChangedAt":"2026-09-15T12:24:24.634Z","schemaVersion":2},"datasetVersion":"2026-09-22T10:30:35.592Z"}