vectordotdev/vector · error

{}

Error message

{}

What it means

`write_event_to_file` encodes each event with the configured framer/encoder; encoding failures (events that don't fit the configured codec, e.g. non-UTF8 or schema-invalid payloads) are converted into `io::ErrorKind::InvalidData` io::Errors, which abort the file sink stream.

Solutions

  1. Check the sink's `encoding` setting matches your data (e.g. use `native_json` or `json` instead of `text` for non-string events).
  2. Add a VRL transform to sanitize/drop events that cannot be encoded.
  3. Inspect the wrapped inner error message to find the offending event shape/field.
  4. Route problematic events to a fallback sink via `remap` with a conditional drop.

Example fix

# before
encoding:
  codec: text   # fails on non-string events

# after
encoding:
  codec: json   # encodes structured events
transform:
  type: remap
  source: '._ = string!(.message)' # normalize payload
Defensive patterns

Strategy: validation

Validate before calling

// validate events are encodable per the sink codec before writing
if encoding == "text" {
    let _ = event.as_string().ok_or("file sink text encoding requires string events")?;
}

Type guard

fn encodable(e: &Event, codec: &str) -> bool {
    codec != "text" || matches!(e, Event::Log(l) if l.get("message").map_or(false, |v| v.is_bytes()))
}

Try / catch

match encoder.encode(&mut event, &mut buffer) {
    Err(e) => {
        error!(message = "Failed to encode file sink event", %e);
        // drop/reroute the event instead of failing the whole stream
    }
    Ok(_) => {},
}

Prevention

When it happens

Trigger: The event fails encoding per the sink's `encoding` config — e.g. feeding non-JSON-serializable values to json encoding, invalid UTF-8 for text encoding, or Avro schema violations.

Common situations: Encoding misconfiguration on the file sink (text vs json vs native_json), events containing malformed/unsupported values after VRL transforms, or framing incompatibilities.

Understand the failure class

Background: "JSON serialization failed", "not JSON serializable", "Failed to serialize": why JSON marshaling errors happen and how to fix them — this error's family across 46 libraries.

Related errors


AI-assisted analysis of vectordotdev/vector@bdb87aeaa4 (2026-09-16). Data as JSON: /api/errors/05e38aab9fba5dd0. Report an issue: GitHub.

Appendix: source

Thrown at src/sinks/file/mod.rs:774

        opts.custom_flags(libc::O_NOFOLLOW);
    }
    #[cfg(not(unix))]
    let _ = confined;

    opts.open(open_path).await.map_err(OpenError::Io)
}

async fn write_event_to_file(
    file: &mut OutFile,
    mut event: Event,
    transformer: &Transformer,
    encoder: &mut Encoder<Framer>,
) -> Result<usize, std::io::Error> {
    transformer.transform(&mut event);
    let mut buffer = BytesMut::new();
    encoder
        .encode(event, &mut buffer)
        .map_err(|error| std::io::Error::new(std::io::ErrorKind::InvalidData, error))?;
    file.write_all(&buffer).await.map(|()| buffer.len())
}

#[async_trait]
impl StreamSink<Event> for FileSink {
    async fn run(mut self: Box<Self>, input: BoxStream<'_, Event>) -> Result<(), ()> {
        FileSink::run(&mut self, input)
            .await
            .expect("file sink error");
        Ok(())
    }
}

#[cfg(test)]
mod tests {
    use std::convert::TryInto;

    use chrono::{SubsecRound, Utc};

View on GitHub (pinned to bdb87aeaa4)