influxdata/influxdb · error · Error::NonUtf8Body

body content is not valid utf8

Error message

body content is not valid utf8: {0}

What it means

`Error::NonUtf8Body` is returned when the request body cannot be decoded as UTF-8. The server reads the body as a Rust String before handling the request, and this error wraps the underlying `Utf8Error` (shown as `{0}`).

Solutions

  1. Ensure the request body is valid UTF-8 before sending; re-encode the file or data (iconv -t utf-8, or set the correct source encoding)
  2. If the payload is compressed, set the Content-Encoding header (e.g. gzip) so the server decodes it rather than parsing it as text
  3. Log/print the raw body bytes around the failing offset to identify the offending characters
  4. Escape or strip non-UTF-8 bytes in the producer before the HTTP call

Example fix

// before (Node)
fetch(url, { method: 'POST', body: fs.readFileSync('lp.bin') });
// after
fetch(url, { method: 'POST', body: fs.readFileSync('lp.bin', 'utf8') });
Defensive patterns

Strategy: validation

Validate before calling

function isUtf8(buf) { try { new TextDecoder('utf-8', { fatal: true }).decode(buf); return true; } catch { return false; } }

Type guard

function isUtf8Buffer(b) { return b instanceof Uint8Array && isUtf8(b); }

Try / catch

try { await send(body); } catch (e) { if (String(e).includes('not valid utf8')) { console.error('re-encode body as UTF-8'); } else throw e; }

Prevention

When it happens

Trigger: POSTing a write_lp/query payload that contains bytes outside valid UTF-8 — e.g. a binary-compressed body sent without Content-Encoding, Latin-1/Windows-1252 encoded files, or corrupted upload data.

Common situations: Scripts that read a line-protocol file with the wrong encoding, sending gzip or other binary data without declaring and applying encoding, copy-pasting characters that got mangled, or clients that prepend BOM/legacy encodings.

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/b0e7e96cc75e56be. Report an issue: GitHub.

Appendix: source

Thrown at influxdb3_server/src/http.rs:200

    fn from(e: AuthenticationError) -> Self {
        Self::Authentication(e)
    }
}

impl From<ResourceAuthorizationError> for RoutingError {
    fn from(e: ResourceAuthorizationError) -> Self {
        Self::Authorization(e)
    }
}

#[derive(Debug, Error)]
pub enum Error {
    /// The requested path has no registered handler.
    #[error("not found")]
    NoHandler,

    /// The request body content is not valid utf8.
    #[error("body content is not valid utf8: {0}")]
    NonUtf8Body(Utf8Error),

    /// The `Content-Encoding` header is invalid and cannot be read.
    #[error("invalid content-encoding header: {0}")]
    NonUtf8ContentEncodingHeader(hyper::header::ToStrError),

    /// The `Content-Type` header is invalid and cannot be read.
    #[error("invalid content-type header: {0}")]
    NonUtf8ContentTypeHeader(hyper::header::ToStrError),

    /// The specified `Content-Encoding` is not acceptable.
    #[error("unacceptable content-encoding: {0}")]
    InvalidContentEncoding(String),

    /// The specified `Content-Type` is not acceptable.
    #[error("unacceptable content-type, expected: {expected}")]
    InvalidContentType { expected: mime::Mime },

View on GitHub (pinned to 06200ef96b)