influxdata/influxdb · error · Error
invalid UTF8 in response
Error message
invalid UTF8 in response: {0} What it means
Error::InvalidUtf8 wraps a std::string::FromUtf8Error produced when the client collects a response body into a String and the bytes are not valid UTF-8. The plaintext/JSON response could not be decoded as text.
Solutions
- Fetch raw bytes and decode explicitly, checking the Content-Type/charset header before conversion.
- Verify no intermediary (proxy/LB) is mangling or compressing the response unexpectedly.
- If the server may emit non-UTF-8, handle bytes with String::from_utf8 manually and report/repair encoding there.
Example fix
// before
let text = resp.text().await?; // -> Error::InvalidUtf8
// after
let bytes = resp.bytes().await?;
let text = String::from_utf8(bytes.to_vec())
.map_err(|e| eprintln!("lossy decode: {}", e))
.unwrap_or_else(|_| String::from_utf8_lossy(&bytes).into_owned()); Defensive patterns
Strategy: try-catch
Validate before calling
// inspect content-type before text conversion
fn is_text(ct: &str) -> bool { ct.starts_with("text/") || ct.contains("json") } Try / catch
match client.call(...).await {
Err(Error::InvalidUtf8(e)) => {
log::warn!("non-UTF8 response: {e}; fetching bytes and lossy-decoding");
decode_lossy_fallback().await
}
other => other,
} Prevention
- Check Content-Type/Content-Encoding headers before decoding as text.
- Bypass or reconfigure proxies that alter response encodings.
- Fall back to from_utf8_lossy for diagnostics while alerting on encoding violations.
When it happens
Trigger: Calling query or metadata APIs whose response body contains non-UTF-8 bytes — e.g. a server or proxy emitting compressed/binary content, charset mismatches, or corrupted responses.
Common situations: Misconfigured proxies returning gzip without content-encoding headers; responses in unexpected encodings; reading binary error pages as text.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- body content is not valid utf8
- Invalid UTF8
- invlid UTF8 received from server
- the mime type specified was not valid UTF8
- the mime type specified was not valid UTF8
AI-assisted analysis of influxdata/influxdb@06200ef96b (2026-09-19).
Data as JSON: /api/errors/6a046511e9931af3.
Report an issue: GitHub.
Appendix: source
Thrown at influxdb3_client/src/lib.rs:47
RequestUrl(#[from] url::ParseError),
#[error("failed to read the API response bytes: {}", reqwest_description(.0))]
Bytes(#[source] reqwest::Error),
#[error("failed to serialize the request body: {0}")]
RequestSerialization(#[source] serde_json::Error),
#[error(
"provided parameter ('{name}') could not be converted \
to a statment parameter"
)]
ConvertQueryParam {
name: String,
#[source]
source: iox_query_params::Error,
},
#[error("invalid UTF8 in response: {0}")]
InvalidUtf8(#[from] FromUtf8Error),
#[error("failed to parse JSON response: {}", reqwest_description(.0))]
Json(#[source] reqwest::Error),
#[error("failed to parse plaintext response: {}", reqwest_description(.0))]
Text(#[source] reqwest::Error),
#[error("server responded with error [{code}]: {message}")]
ApiError {
code: StatusCode,
message: String,
/// Machine-readable error code from JSON error responses, if present.
error_code: Option<String>,
},
#[error("failed to send {method} {url} request: {}", reqwest_description(.source))]
RequestSend {View on GitHub (pinned to 06200ef96b)