diegosouzapw/OmniRoute · error
Grok returned an invalid device code
Error message
Grok returned an invalid device code
What it means
The user_code returned by Grok's device authorization endpoint failed the ^[A-Za-z0-9-]+$ format check. The upstream returned a 2XX response with string fields, but the user_code contains characters outside alphanumeric+hyphen — indicating a malformed or corrupted code that would be unusable for the user verification step anyway.
Solutions
- Inspect the raw user_code value to see which unexpected characters it contains
- Check whether Grok changed the user_code format (e.g. added spaces or new separators) and widen the regex if intentional
- Retry the device authorization request — upstream corruption is usually transient
- Report to Grok if the format is consistently invalid
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at src/lib/oauth/providers/grok-cli.ts:133 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of diegosouzapw/OmniRoute@a179ffed5b (2026-08-25).
Data as JSON: /api/errors/6f17c2b20c3534ad.
Report an issue: GitHub.
Appendix: source
Thrown at src/lib/oauth/providers/grok-cli.ts:133
});
const data = await parseOAuthResponse(response);
if (!response.ok) {
throw new Error(
typeof data.error_description === "string"
? data.error_description
: "Grok device authorization failed"
);
}
if (
typeof data.device_code !== "string" ||
typeof data.user_code !== "string" ||
typeof data.verification_uri !== "string"
) {
throw new Error("Grok device authorization response is incomplete");
}
if (!/^[A-Za-z0-9-]+$/.test(data.user_code)) {
throw new Error("Grok returned an invalid device code");
}
validateVerificationUri(data.verification_uri);
if (typeof data.verification_uri_complete === "string") {
validateVerificationUri(data.verification_uri_complete);
}
return {
device_code: data.device_code,
user_code: data.user_code,
verification_uri: data.verification_uri,
verification_uri_complete:
typeof data.verification_uri_complete === "string"
? data.verification_uri_complete
: data.verification_uri,
expires_in: typeof data.expires_in === "number" ? data.expires_in : 1800,
interval: typeof data.interval === "number" ? data.interval : 5,
};
}View on GitHub (pinned to a179ffed5b)