influxdata/influxdb · error · Error

the mime type specified was not valid UTF8

Error message

the mime type specified was not valid UTF8: {0}

What it means

Error::NonUtf8MimeType in influxdb3_types::http is thrown when the raw mime type bytes are not valid UTF-8. It wraps std::string::FromUtf8Error via #[from], so any FromUtf8Error encountered while converting a mime type into a String is converted automatically. Valid media types must be UTF-8 encodable to be handled.

Solutions

  1. Ensure the client/gateway sends ASCII/UTF-8 Content-Type headers
  2. Re-encode or sanitize the incoming header bytes to lossy UTF-8 before parsing
  3. Reject or log-and-drop requests with non-UTF-8 headers at the edge

Example fix

// before
let mime = String::from_utf8(bytes)?; // panics into error on bad bytes
// after
let mime = String::from_utf8_lossy(&bytes).to_string(); // or reject request with 400
Defensive patterns

Strategy: validation

Validate before calling

fn header_is_utf8(bytes: &[u8]) -> bool {
    std::str::from_utf8(bytes).is_ok()
}

Type guard

fn lossy_mime(bytes: &[u8]) -> Option<String> {
    std::str::from_utf8(bytes).ok().map(|s| s.to_string())
}

Try / catch

match result {
    Ok(v) => v,
    Err(Error::NonUtf8MimeType(src)) => /* 400 Bad Request: non-UTF-8 Content-Type */,
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: Converting header/body bytes to a String when the Content-Type value contains non-UTF-8 bytes (e.g. latin-1 encoded bytes, binary garbage) and the FromUtf8Error is converted into this Error.

Common situations: Clients with broken encoders sending non-ASCII bytes in headers, gateways mangling Content-Type, legacy systems using ISO-8859-1 header values.

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


AI-assisted analysis of influxdata/influxdb@06200ef96b (2026-09-19). Data as JSON: /api/errors/f3ebe1697c907bff. Report an issue: GitHub.

Appendix: source

Thrown at influxdb3_types/src/http.rs:63

    where
        D: serde::Deserializer<'a>,
    {
        let s = String::deserialize(deserializer)?;
        match s.as_str() {
            "never" => Ok(Self::Never),
            "now" => Ok(Self::Now),
            "default" => Ok(Self::Default),
            timestamp => Ok(Self::Timestamp(timestamp.to_string())),
        }
    }
}

#[derive(Debug, thiserror::Error)]
pub enum Error {
    #[error("invalid mime type ({0})")]
    InvalidMimeType(String),

    #[error("the mime type specified was not valid UTF8: {0}")]
    NonUtf8MimeType(#[from] std::string::FromUtf8Error),

    #[error(transparent)]
    Unexpected(#[from] anyhow::Error),
}

impl From<&Error> for hyper::StatusCode {
    fn from(value: &Error) -> Self {
        match value {
            Error::InvalidMimeType(_) | Error::NonUtf8MimeType(_) => Self::BAD_REQUEST,
            Error::Unexpected(_) => Self::INTERNAL_SERVER_ERROR,
        }
    }
}

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct PingResponse {
    #[serde(default)]

View on GitHub (pinned to 06200ef96b)