vectordotdev/vector · error

should not fail to encode input event

Error message

should not fail to encode input event

What it means

During component validation, test events are encoded with the configured encoder before being fed to the component under test. Encoding of well-formed TestEvent payloads is assumed infallible, so the result is unwrapped with `expect`. A panic here means the encoder rejected an event it should always handle — an encoder/serializer incompatibility.

Solutions

  1. Switch the validation test's encoder to one compatible with the test events (e.g. json codec)
  2. Check the TestEvent payload for fields the chosen encoder can't represent and simplify it
  3. Update Vector; if the default codec fails, report the failing serializer

Example fix

// before
[components.test_event]
encoder = { codec = "avro", schema = "..." }
// after
[components.test_event]
encoder = { codec = "json" }
Defensive patterns

Strategy: validation

Validate before calling

// Prefer codecs known to encode test events:
// ensure encoder.codec in ["json","text","ndjson"] before running validation

Prevention

When it happens

Trigger: `encode_test_event` is called by the validation input HTTP server/client or the input driver with a TestEvent whose variant requires normal encoding, and `encoder.encode` returns Err — e.g. an encoder/serializer combination that cannot serialize the event's shape (unsupported event types, charset issues).

Common situations: Using an encoder (e.g. Avro, native JSON with strict schema) in validation tests whose serializer rejects the generated test event; mismatch between the configured codec and the test event structure.

Understand the failure class

Background: json.Marshal / "failed to marshal" errors in Go: why "unsupported type" happens and how to fix it — this error's family across 22 libraries.

Related errors


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

Appendix: source

Thrown at src/components/validation/resources/event.rs:164

            } => TestEvent::FailWithAlternateEncoder(event_data.into_event()),
            RawTestEvent::ResourceReject {
                external_resource_rejects: event_data,
            } => TestEvent::FailWithExternalResource(event_data.into_event()),
        }
    }
}

pub fn encode_test_event(
    encoder: &mut Encoder<encoding::Framer>,
    buf: &mut BytesMut,
    event: TestEvent,
) {
    match event {
        TestEvent::Passthrough(event) | TestEvent::FailWithExternalResource(event) => {
            // Encode the event normally.
            encoder
                .encode(event, buf)
                .expect("should not fail to encode input event");
        }
        TestEvent::FailWithAlternateEncoder(event) => {
            // This is a little fragile, but we check what serializer this encoder uses, and based
            // on `Serializer::supports_json`, we choose an opposing codec. For example, if the
            // encoder supports JSON, we'll use a serializer that doesn't support JSON, and vise
            // versa.
            let mut alt_encoder = if encoder.serializer().supports_json() {
                Encoder::<encoding::Framer>::new(
                    LengthDelimitedEncoder::default().into(),
                    LogfmtSerializer.into(),
                )
            } else {
                Encoder::<encoding::Framer>::new(
                    NewlineDelimitedEncoder::default().into(),
                    JsonSerializer::new(
                        MetricTagValues::default(),
                        JsonSerializerOptions::default(),
                    )

View on GitHub (pinned to bdb87aeaa4)