Hmbown/CodeWhale · error
missing
Error message
{key} missing What it means
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.
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.
Example fix
// before (executor.rs)
let value = env.get("DEEPSEEK_MSG").unwrap_or_else(|| panic!("{key} missing"));
// after (key aligned with to_env_vars output)
let value = env.get("DEEPSEEK_MESSAGE").unwrap_or_else(|| panic!("{key} missing")); Defensive patterns
Strategy: validation
Validate before calling
let env = builder.to_env_vars();
for key in ["DEEPSEEK_ERROR", "DEEPSEEK_MESSAGE", "DEEPSEEK_TOOL_RESULT"] {
assert!(env.contains_key(key), "{key} not emitted by to_env_vars");
} Type guard
fn emitted(env: &HashMap<String, String>, key: &str) -> bool { env.contains_key(key) } Try / catch
match env.get(key) {
Some(v) => assert!(v.ends_with("...[truncated]")),
None => panic!("{key} missing from to_env_vars output"),
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.
Related errors
AI-assisted analysis of Hmbown/CodeWhale@433685b202 (2026-09-15).
Data as JSON: /api/errors/b0e15e3ca56f429d.
Report an issue: GitHub.
Appendix: source
Thrown at crates/tui/src/hooks/executor.rs:4946
assert_eq!(
without_code.get("DEEPSEEK_TOOL_SUCCESS"),
Some(&"false".to_string())
);
}
#[test]
fn payload_env_vars_are_bounded() {
// Errors used to be the one unbounded field; a failed `exec_shell`
// could push its whole output into `DEEPSEEK_ERROR`.
let long = "x".repeat(20_000);
let env = HookContext::new()
.with_error(&long)
.with_message(&long)
.with_tool_result(&long, false, None)
.to_env_vars();
for key in ["DEEPSEEK_ERROR", "DEEPSEEK_MESSAGE", "DEEPSEEK_TOOL_RESULT"] {
let value = env.get(key).unwrap_or_else(|| panic!("{key} missing"));
assert!(value.len() < 20_000, "{key} was not truncated");
assert!(value.ends_with("...[truncated]"), "{key} lost its marker");
}
}
#[test]
fn truncate_env_value_respects_utf8_boundaries() {
// 4-byte characters straddling the cap must not panic or split.
let value = "🐋".repeat(100);
let truncated = super::truncate_env_value(&value, 10);
assert!(truncated.ends_with("...[truncated]"));
let head = truncated.trim_end_matches("...[truncated]");
assert!(head.chars().all(|c| c == '🐋'));
assert!(head.len() <= 12);
}
#[cfg(unix)]
#[test]View on GitHub (pinned to 433685b202)