vectordotdev/vector · error
should not fail to encode output event
Error message
should not fail to encode output event
What it means
The output driver optionally encodes each received output event using the provided encoder (e.g. a codec configured for the test) to compute received-bytes metrics. Encoding is expected to succeed for any event that the topology produced, so an Err aborts with this expect. It indicates an encoder/event incompatibility rather than a test logic failure.
Solutions
- Log the encoding error and the offending event (replace expect with unwrap_or_else) to see the incompatible value.
- Choose a codec in the test's encoding config that supports all value types the component emits (e.g. JSON with fallible handling).
- If a codec upgrade caused it, adjust the event normalization or pin/patch the codec version.
Defensive patterns
Strategy: try-catch
Validate before calling
// ensure codec supports all value types the component can emit before the test assert!(encoder_supports(&output_event), "codec cannot encode event");
Try / catch
encoder.clone().encode(output_event, &mut buffer)
.unwrap_or_else(|e| panic!("encode failed for event {output_event:?}: {e}")); Prevention
- Pick a codec in the test encoding config that covers every value type the component emits.
- Avoid routing binary/non-UTF-8 values through text-only encoders in validation tests.
- Pin and review codec dependency upgrades for added strictness.
When it happens
Trigger: spawn_output_driver receiving an event the configured encoder cannot serialize — e.g. a JSON/text codec asked to encode an event containing non-UTF-8 bytes, unsupported value types after a codec change, or a codec with strict serialization rules (e.g. Avro schema mismatch).
Common situations: Validation tests using an encoding config whose codec can't represent all event value types produced by the transform under test; codec library upgrades adding strictness; events containing binary/regex-derived values passed through a text encoder.
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
- should not fail to encode input event
- Timestamp out of range
- a sink must always have an external resource
- a source must always have an external resource
- breaking fragment ' ' has an invalid anchor ' '. Add ` }`…
AI-assisted analysis of vectordotdev/vector@bdb87aeaa4 (2026-09-16).
Data as JSON: /api/errors/e02996d17fae0d60.
Report an issue: GitHub.
Appendix: source
Thrown at src/components/validation/runner/mod.rs:693
output_events.extend(events.clone());
// Update the runner metrics for the received event. This will later
// be used in the Validators, as the "expected" case.
let mut output_runner_metrics = output_runner_metrics.lock().await;
if component_type != ComponentType::Sink {
for output_event in events {
// The event is wrapped in a Vec to match the actual event storage in
// the real topology
output_runner_metrics.received_event_bytes_total +=
vec![&output_event].estimated_json_encoded_size_of().get() as u64;
if let Some(encoder) = maybe_encoder.as_ref() {
let mut buffer = BytesMut::new();
encoder
.clone()
.encode(output_event, &mut buffer)
.expect("should not fail to encode output event");
output_runner_metrics.received_events_total += 1;
output_runner_metrics.received_bytes_total += buffer.len() as u64;
}
}
}
if output_events.len() >= expected_events {
info!("Output driver has received all expected events.");
break
}
} else {
// The channel closed on us.
// This shouldn't happen because in the runner we should not shutdown the external
// resource until this output driver task is complete.
error!("Output driver channel with external resource closed.");
break
}
}View on GitHub (pinned to bdb87aeaa4)