{"record":{"id":"ab24a4e792843d42","repo":"Hmbown/CodeWhale","slug":"unavailable-credential","errorCode":null,"errorMessage":"unavailable credential","messagePattern":"unavailable credential","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/cli/src/credential_handoff.rs","lineNumber":65,"sourceCode":"                .auth_mode\n                .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":47,"sourceCodeEnd":75,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/cli/src/credential_handoff.rs#L47-L75","documentation":"handoff_secret_line resolves a credential via a caller-supplied closure and writes it to stdout for a pipe consumer. Any error from the resolver is collapsed into the generic message \"unavailable credential\" so that the secret source and OS error details never leak to output. It signals the credential could not be retrieved at handoff time.","triggerScenarios":"The `resolve` closure passed to handoff_secret_line returns Err — e.g. the auth store has no API key for the selected provider, the keyring/backend read fails, or config loading failed before resolution.","commonSituations":"Running a piped command that hands off an API key when the provider was never logged in, the credential was revoked/deleted, or a headless CI environment lacks the secret store the desktop login populated.","solutions":["Log in / set the credential for the selected provider before piping (run the interactive auth flow once)","Verify the provider/profile selected is the one that actually has a key configured","Check that the OS secret service (keyring/agent) is reachable in the current environment","Inspect upstream logs for the redacted underlying resolver error"],"exampleFix":"// before: piping handoff with no stored credential\n$ codewhale auth ... --pipe | consumer\n// after: ensure credential exists first\n$ codewhale login\n$ codewhale auth ... --pipe | consumer","handlingStrategy":"try-catch","validationCode":"// before piping, confirm a credential is resolvable\nif resolve().is_err() {\n    eprintln!(\"no stored credential for selected provider; run the login flow first\");\n}","typeGuard":null,"tryCatchPattern":"match handoff_secret_line(&mut out, is_tty, resolve) {\n    Ok(()) => {},\n    Err(e) if e.to_string() == \"unavailable credential\" => {\n        eprintln!(\"credential unavailable — run `codewhale login` before piping\");\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Run the interactive login once before scripting piped handoffs","In CI, provision credentials explicitly (env/file secret store) rather than relying on a desktop keyring","Never assume pipe failures include secret details — the message is intentionally redacted; log the resolver outcome separately on success/failure"],"tags":["cli","credentials","redaction"],"backgroundTag":"missing-credentials","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"}