Hmbown/CodeWhale · error
refusing oversized xAI OAuth credential payload
Error message
refusing oversized xAI OAuth credential payload
What it means
write() refuses any payload larger than XAI_OAUTH_FILE_LIMIT bytes before touching disk. The credential store enforces a hard size ceiling on the files it owns to bound read sizes and prevent abuse. The write is aborted with no file created or replaced.
Solutions
- Trim the payload to only the credential document the store expects.
- Check bytes.len() against the limit before calling and surface a clearer application-level error.
- Split oversized data into separate storage outside the credential store.
- Update the caller that is assembling the payload if it recently changed.
Example fix
// before store.write(name, entire_response_body.as_bytes(), true)?; // after anyhow::ensure!(entire_response_body.len() < XAI_OAUTH_FILE_LIMIT, "payload too large"); store.write(name, token_document.as_bytes(), true)?;
Defensive patterns
Strategy: validation
Validate before calling
anyhow::ensure!(payload.len() as u64 <= XAI_OAUTH_FILE_LIMIT, "payload {} exceeds limit", payload.len()); Prevention
- Write only the minimal credential document, not whole API responses
- Check payload size in tests that construct token blobs
- Assert byte lengths after any JSON transformation before writing
When it happens
Trigger: Calling XaiOAuthCredentialStore::write with a bytes slice whose length as u64 exceeds XAI_OAUTH_FILE_LIMIT.
Common situations: Passing an entire OAuth token response JSON instead of just the token file contents; accidentally writing a bundle of credentials; a bug concatenating files.
Understand the failure class
Background: "File too large" / "file size exceeds limit" errors: why libraries cap file sizes and how to fix them — this error's family across 46 libraries.
Related errors
- api_key cannot be empty string
- bundle at is bytes; the limit is bytes
- Choose an appearance file smaller than 4 KiB.
- Choose an appearance file smaller than 4 KiB.
- Codewhale-owned credential file
AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22).
Data as JSON: /api/errors/58805af9f2394bf9.
Report an issue: GitHub.
Appendix: source
Thrown at crates/config/src/xai_credentials.rs:263
})?;
if bytes.len() as u64 > XAI_OAUTH_FILE_LIMIT {
bail!(
"Codewhale-owned xAI OAuth file {} exceeds the {} byte limit",
crate::quote_os_path(&self.directory.join(name)),
XAI_OAUTH_FILE_LIMIT
);
}
String::from_utf8(bytes).map(Some).map_err(|_| {
anyhow::anyhow!(
"Codewhale-owned xAI OAuth file {} is not valid UTF-8",
crate::quote_os_path(&self.directory.join(name))
)
})
}
pub fn write(&self, name: &str, bytes: &[u8], allow_replace: bool) -> Result<()> {
validate_owned_auth_name(name)?;
anyhow::ensure!(
bytes.len() as u64 <= XAI_OAUTH_FILE_LIMIT,
"refusing oversized xAI OAuth credential payload"
);
self.write_owned_file(name, bytes, allow_replace)
}
pub fn remove(&self, name: &str) -> Result<bool> {
validate_owned_auth_name(name)?;
self.remove_raw(name)
}
pub fn clear_all(&self) -> Result<usize> {
let mut removed = 0;
for name in self.owned_auth_names()? {
if self.remove(&name)? {
removed += 1;
}
}View on GitHub (pinned to 73e0f67d83)