Hmbown/CodeWhale · warning

serialize fixture

Error message

serialize fixture

What it means

A panic from `serde_json::to_vec(...).expect("serialize fixture")` in the Codex credential-snapshot test. The test builds a JSON payload ({"tokens": {"access_token", "account_id"}}) via serde_json::json! and serializes it before writing auth.json. Serialization of an in-memory json! value is infallible in practice, so a failure here indicates a serde_json internal issue (or an out-of-memory condition), not bad input.

Solutions

  1. Re-run the test — transient allocation failures usually disappear; check for OOM in dmesg/CI logs.
  2. Run `cargo update -p serde_json` or `cargo check` to ensure a single consistent serde_json version in the lockfile.
  3. If reproducible, report/inspect the exact json! literal for map-key collisions introduced by local edits.
  4. Increase CI memory limits if the machine is near OOM.
Defensive patterns

Strategy: try-catch

Try / catch

let bytes = serde_json::to_vec(&value)
    .unwrap_or_else(|e| panic!("serialize fixture: {e}"));

Prevention

When it happens

Trigger: `serde_json::to_vec(&serde_json::json!({...})).expect("serialize fixture")` returns Err — practically only on allocation failure or a broken serde_json build; the value being serialized is a fixed literal shape.

Common situations: Running tests in a memory-limited container; a dependency upgrade that mixes incompatible serde/serde_json versions.

Understand the failure class

Background: "JSON serialization failed", "not JSON serializable", "Failed to serialize": why JSON marshaling errors happen and how to fix them — this error's family across 46 libraries.

Related errors


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

Appendix: source

Thrown at crates/tui/src/client.rs:8262

        "sakana-config-secret-008",
    ];

    #[test]
    fn codex_client_uses_one_coherent_external_credential_snapshot() {
        let _env = crate::test_support::lock_test_env();
        let temp = tempfile::tempdir().expect("credential fixture");
        let path = temp
            .path()
            .canonicalize()
            .expect("canonical temp root")
            .join("auth.json");
        let token_a = crate::test_support::future_test_jwt("a");
        std::fs::write(
            &path,
            serde_json::to_vec(&serde_json::json!({
                "tokens": {"access_token": token_a.clone(), "account_id": "account-a"}
            }))
            .expect("serialize fixture"),
        )
        .expect("write fixture");
        let _auth_path = crate::test_support::EnvVarGuard::set("OPENAI_CODEX_AUTH_FILE", &path);
        let _access = crate::test_support::EnvVarGuard::remove("OPENAI_CODEX_ACCESS_TOKEN");
        let _legacy_access = crate::test_support::EnvVarGuard::remove("CODEX_ACCESS_TOKEN");
        let config = Config {
            provider: Some(ApiProvider::OpenaiCodex.as_str().to_string()),
            providers: Some(ProvidersConfig {
                openai_codex: ProviderConfig {
                    auth_mode: Some("oauth".to_string()),
                    external_credentials: Some(
                        codewhale_config::ExternalCredentialConsentToml::read_only(
                            codewhale_config::ProviderKind::OpenaiCodex,
                            codewhale_config::ExternalCredentialSource::CodexCli,
                            path.clone(),
                        ),
                    ),
                    ..ProviderConfig::default()

View on GitHub (pinned to 73e0f67d83)