Hmbown/CodeWhale · error

expected authentication error, got

Error message

expected authentication error, got {other}

What it means

Test helper panic in the LLM client's auth-message tests. auth_user_message takes an LlmError and only handles LlmError::AuthenticationError; any other variant (rate limit, network, API error) hits the catch-all panic. It exists so a test author passing the wrong LlmError variant fails loudly instead of testing the wrong message path.

Solutions

  1. Check which test calls auth_user_message and fix the LlmError it constructs to be LlmError::AuthenticationError.
  2. If the client now surfaces a different variant for auth failures, update both the helper and the expectation.
  3. Optionally have the panic print Debug of `other` for quick diagnosis.

Example fix

// before
other => panic!("expected authentication error, got {other}"),
// after
other => panic!("expected authentication error, got {other:?} — the client now maps auth failures to a different LlmError variant"),
Defensive patterns

Strategy: type-guard

Validate before calling

// ensure the constructed error is the auth variant before calling the helper
assert!(matches!(err, LlmError::AuthenticationError(_)), "helper requires AuthenticationError, got {err:?}");

Type guard

fn is_auth_error(e: &LlmError) -> bool { matches!(e, LlmError::AuthenticationError(_)) }

Try / catch

match error { LlmError::AuthenticationError(a) => a.to_user_message(), other => panic!("expected authentication error, got {other:?}") }

Prevention

When it happens

Trigger: A test calls auth_user_message with an LlmError that is not LlmError::AuthenticationError — typically after refactoring where a helper now receives a different error variant.

Common situations: Changing which error a retry/client path produces (e.g. from AuthenticationError to ApiError) without updating the helper's caller; copy-paste of a helper call across tests.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@433685b202 (2026-09-15). Data as JSON: /api/errors/225b5bf4bcd7f338. Report an issue: GitHub.

Appendix: source

Thrown at crates/tui/src/llm_client/mod.rs:1380

mod quota_tests;

// === Tests ===

#[cfg(test)]
mod tests {
    use super::*;

    fn assert_f64_eq(actual: f64, expected: f64) {
        assert!(
            (actual - expected).abs() < f64::EPSILON,
            "expected {expected}, got {actual}"
        );
    }

    fn auth_user_message(error: LlmError) -> String {
        match error {
            LlmError::AuthenticationError(auth) => auth.to_user_message(),
            other => panic!("expected authentication error, got {other}"),
        }
    }

    #[test]
    fn test_retry_config_defaults() {
        let config = RetryConfig::default();
        assert!(config.enabled);
        assert_eq!(config.max_retries, 3);
        assert_f64_eq(config.initial_delay, 1.0);
        assert_f64_eq(config.max_delay, 60.0);
        assert_f64_eq(config.exponential_base, 2.0);
        assert!(config.jitter);
    }

    #[test]
    fn test_retry_config_disabled() {
        let config = RetryConfig::disabled();
        assert!(!config.enabled);

View on GitHub (pinned to 433685b202)