{"record":{"id":"76608f8e607c55cb","repo":"Hmbown/CodeWhale","slug":"credential-handoff-was-empty","errorCode":null,"errorMessage":"credential handoff was empty","messagePattern":"credential handoff was empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/cli/src/credential_handoff.rs","lineNumber":66,"sourceCode":"                .as_deref()\n                .is_some_and(auth_mode_uses_kimi_imported_token);\n        ensure!(!kimi_bearer, \"bearer credentials are not an API key\");\n    }\n    ensure!(source.is_some(), \"no runtime-effective API key\");\n    resolved\n        .api_key\n        .filter(|value| !value.trim().is_empty())\n        .context(\"no usable runtime-effective API key\")\n}\n\npub(crate) fn handoff_secret_line(\n    writer: &mut impl Write,\n    stdout_is_terminal: bool,\n    resolve: impl FnOnce() -> Result<String>,\n) -> Result<()> {\n    prepare_stdout(stdout_is_terminal)?;\n    let secret = Zeroizing::new(resolve().map_err(|_| anyhow::anyhow!(\"unavailable credential\"))?);\n    ensure!(!secret.trim().is_empty(), \"credential handoff was empty\");\n    let written = writeln!(writer, \"{}\", secret.as_str());\n    if written.is_ok() || written.is_err_and(|error| error.kind() == ErrorKind::BrokenPipe) {\n        return Ok(());\n    }\n    bail!(\"credential handoff could not write to stdout\")\n}\n#[cfg(test)]\nmod tests;\n","sourceCodeStart":48,"sourceCodeEnd":75,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/cli/src/credential_handoff.rs#L48-L75","documentation":"handoff_secret_line refuses to write a credential to stdout when the resolver returned a value that is empty or whitespace-only. The handoff contract is that exactly one non-empty secret line is piped to the consumer, so an empty resolution fails closed before anything is written. Note the resolver's own error is already redacted to 'unavailable credential', so this check is the last guard against a blank secret.","triggerScenarios":"The resolve closure passed to handoff_secret_line returns Ok with an empty or all-whitespace string — e.g. a secret-store entry exists but stores an empty value, or a config file has a blank api_key field that passed earlier presence checks.","commonSituations":"A credential was created in the shared secret store with an empty value; a config migration or editor stripped the key's content; an env var is set to \"\" which some sources treat as present-but-empty.","solutions":["Re-set the credential with its actual value in whichever source supplies it (secret store entry, env var, or config field).","Inspect the secret store entry for the provider — delete and recreate it if it is empty.","If your tooling may write blank values, trim/validate on write so empty credentials never persist."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if secret.trim().is_empty() {\n    return Err(\"credential for provider X is empty; re-run setup\");\n}","typeGuard":"fn is_non_blank(s: &Option<String>) -> bool {\n    s.as_deref().map(|v| !v.trim().is_empty()).unwrap_or(false)\n}","tryCatchPattern":null,"preventionTips":["Validate credentials are non-blank when writing them to the secret store.","Treat empty-string env vars as absent in provisioning scripts.","Audit secret-store entries after config migrations."],"tags":["cli","credentials","empty-value","stdout-pipe"],"backgroundTag":"empty-required-field","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}