Hmbown/CodeWhale · error

operation_key cannot contain leading or trailing whitespace

Error message

operation_key cannot contain leading or trailing whitespace

What it means

validate_runtime_turn_operation_key rejects operation keys with leading or trailing whitespace (value.trim() != value). Keys are used as canonical identifiers and fingerprint inputs, so untrimmed values would create divergent identities for the same logical operation.

Solutions

  1. Call .trim() on the key before passing it
  2. Fix the source (config line, env var, template) that introduces the whitespace
  3. Add a trim+assert step in your key-construction helper

Example fix

// before
let key = env::var("CODEWHALE_OP_KEY")?;
// after
let key = env::var("CODEWHALE_OP_KEY")?.trim().to_string();
Defensive patterns

Strategy: validation

Validate before calling

let key = candidate.trim();
assert_eq!(key, candidate, "operation_key must not have surrounding whitespace");

Prevention

When it happens

Trigger: Passing an operation_key that begins or ends with space/tab/newline — commonly from user-supplied config values, CLI args pasted with trailing spaces, or string templates that append a newline.

Common situations: Reading a key from a config file or env var without trimming; format! templates ending in '\n'; copy-pasted keys with a trailing space.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22). Data as JSON: /api/errors/2a664f564d4ae9b9. Report an issue: GitHub.

Appendix: source

Thrown at crates/tui/src/runtime_threads.rs:3505

#[derive(Debug, thiserror::Error)]
pub(crate) enum RuntimeTurnOperationLookupError {
    #[error("Invalid thread id or operation key")]
    InvalidRequest,
    #[error("Turn operation acceptance is incomplete; retry lookup")]
    Incomplete,
    #[error("Turn operation lookup unavailable")]
    Unavailable,
}

fn validate_runtime_turn_operation_key(value: &str) -> Result<()> {
    if value.is_empty() {
        bail!("operation_key cannot be empty");
    }
    if value.len() > MAX_RUNTIME_TURN_OPERATION_KEY_BYTES {
        bail!("operation_key cannot exceed {MAX_RUNTIME_TURN_OPERATION_KEY_BYTES} UTF-8 bytes");
    }
    if value.trim() != value {
        bail!("operation_key cannot contain leading or trailing whitespace");
    }
    if value.chars().any(char::is_control) {
        bail!("operation_key cannot contain control characters");
    }
    Ok(())
}

fn validate_sha256_fingerprint(value: &str, label: &str) -> Result<()> {
    if value.len() != 64 || !value.bytes().all(|byte| byte.is_ascii_hexdigit()) {
        bail!("{label} must be a SHA-256 hex digest");
    }
    Ok(())
}

fn runtime_turn_operation_key_fingerprint(
    owner_id: &str,
    thread_id: &str,
    operation_key: &str,

View on GitHub (pinned to 73e0f67d83)