influxdata/influxdb · error · Error
to str error
Error message
to str error: {0} What it means
Wraps hyper::header::ToStrError via #[from]. HTTP header values are byte slices; converting one to &str fails if it contains non-ASCII bytes. The server rejects such requests with 'to str error: ...'.
Solutions
- Send header values as printable ASCII only
- If a token must carry binary data, base64-encode it (standard charset)
- Fix the client that generates the offending header
- Capture the raw request to identify which header contains non-ASCII bytes
Example fix
// before
request.headers.set("Authorization", "Basic " + rawBytes) // raw non-ascii bytes
// after
request.headers.set("Authorization", "Basic " + btoa(username + ":" + password)) Defensive patterns
Strategy: validation
Validate before calling
for (const [k, v] of Object.entries(headers)) {
if (!/^[\x20-\x7E]*$/.test(v)) throw new Error(`header ${k} has non-ASCII bytes`);
} Type guard
function isAsciiHeaderValue(v) { return typeof v === "string" && /^[\x20-\x7E]*$/.test(v); } Try / catch
try { await send(req); } catch (e) {
if (String(e).includes("to str error")) {
// locate the non-ASCII header, sanitize, resend
}
} Prevention
- Base64-encode tokens instead of embedding raw bytes in headers
- Restrict header construction to string constants and validated values
- Reject non-ASCII header input at the client boundary
- Capture raw requests when debugging header-related 400s
When it happens
Trigger: Any request whose header (e.g. Authorization, Content-Type, Accept) contains bytes outside valid ASCII/UTF-8 when the handler calls header.to_str().
Common situations: Clients that base64-decode incorrectly into raw bytes for Authorization; legacy encoders using ISO-8859-1 in headers; corrupted requests from proxies.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- the mime type specified was not valid UTF8
- body content is not valid utf8
- hyper error
- hyper http error
- invalid content-encoding header
AI-assisted analysis of influxdata/influxdb@06200ef96b (2026-09-19).
Data as JSON: /api/errors/593f0f1c0697d418.
Report an issue: GitHub.
Appendix: source
Thrown at influxdb3_server/src/http.rs:303
/// Arrow error
#[error("arrow error: {0}")]
Arrow(#[from] arrow::error::ArrowError),
/// Hyper error
#[error("hyper http error: {0}")]
Hyper(#[from] hyper::http::Error),
/// WriteBuffer error
#[error("write buffer error: {0}")]
WriteBuffer(#[from] influxdb3_write::write_buffer::Error),
/// Persister error
#[error("persister error: {0}")]
Persister(#[from] influxdb3_write::persister::PersisterError),
// ToStrError
#[error("to str error: {0}")]
ToStr(#[from] hyper::header::ToStrError),
// SerdeJsonError
#[error("serde json error: {0}")]
SerdeJson(#[from] serde_json::Error),
// Influxdb3 Write
#[error("serde json error: {0}")]
Influxdb3Write(#[from] influxdb3_write::Error),
#[error("datafusion error: {0}")]
Datafusion(#[from] DataFusionError),
#[error("io error: {0}")]
Io(#[from] std::io::Error),
#[error("query error: {0}")]
Query(#[from] QueryExecutorError),View on GitHub (pinned to 06200ef96b)