{"record":{"id":"561c9209c576e757","repo":"nikivdev/code","slug":"unexpected-auth-status","errorCode":null,"errorMessage":"unexpected auth status: {}","messagePattern":"unexpected auth status: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/auth.rs","lineNumber":102,"sourceCode":"        }\n\n        let poll: DevicePollResponse = poll_response\n            .json()\n            .context(\"failed to parse device auth poll response\")?;\n\n        match poll.status.as_str() {\n            \"approved\" => {\n                let token = poll\n                    .token\n                    .ok_or_else(|| anyhow!(\"device auth approved without token\"))?;\n                env::save_ai_auth_token(token, Some(api_url.clone()))?;\n                println!(\"✓ Auth complete. You're ready to use Flow AI.\");\n                return Ok(());\n            }\n            \"pending\" => continue,\n            \"expired\" => bail!(\"device code expired. Run `f auth` again.\"),\n            \"invalid\" => bail!(\"device code invalid. Run `f auth` again.\"),\n            other => bail!(\"unexpected auth status: {}\", other),\n        }\n    }\n\n    bail!(\"device code expired. Run `f auth` again.\")\n}\n\nfn open_in_browser(url: &str) {\n    #[cfg(target_os = \"macos\")]\n    {\n        let _ = std::process::Command::new(\"open\").arg(url).status();\n    }\n\n    #[cfg(target_os = \"linux\")]\n    {\n        let _ = std::process::Command::new(\"xdg-open\").arg(url).status();\n    }\n\n    #[cfg(not(any(target_os = \"macos\", target_os = \"linux\")))]","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/auth.rs#L84-L120","documentation":"In `login` (src/auth.rs:102) the device-flow poll loop matches known statuses (success, pending, expired, invalid) and bails on any other value via `other => bail!(\"unexpected auth status: {}\", other)`. This is a forward-compatibility guard: the server returned a status string this CLI version does not understand. It usually indicates a server/client protocol mismatch.","triggerScenarios":"The poll endpoint returns a status string other than \"pending\"/\"expired\"/\"invalid\"/success — e.g. a new server-side status like \"slow_down\" or \"denied\" added after this CLI version shipped, or a malformed response body.","commonSituations":"Auth server was updated to a newer protocol than the installed CLI; a proxy returns an HTML/error page parsed as an odd status; response shape changed between API versions.","solutions":["Upgrade the CLI to the latest version so it understands new auth statuses","Check the printed status value for clues about what the server returned","Verify the configured auth API URL points at the compatible server version","If behind a proxy, bypass it and retry `f auth`"],"exampleFix":"// before\nother => bail!(\"unexpected auth status: {}\", other),\n// after\n\"slow_down\" => { std::thread::sleep(Duration::from_secs(5)); continue; }\nother => bail!(\"unexpected auth status: {}\", other),","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match result {\n    Err(e) if e.to_string().starts_with(\"unexpected auth status\") => {\n        log_server_status(&e); // capture the raw status for diagnosis\n        eprintln!(\"CLI/server protocol mismatch — upgrade the CLI\");\n    }\n    other => other?,\n}","preventionTips":["Auto-update or pin CLI versions compatible with your auth server","Log unexpected statuses to spot new server states early","Test auth flows after any server deployment"],"tags":["auth","protocol-mismatch","version-skew"],"backgroundTag":"unexpected-server-response","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}