{"record":{"id":"bbc087ad05cfc8e0","repo":"vectordotdev/vector","slug":"should-not-fail-to-encode-input-event","errorCode":null,"errorMessage":"should not fail to encode input event","messagePattern":"should not fail to encode input event","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/components/validation/resources/event.rs","lineNumber":164,"sourceCode":"            } => TestEvent::FailWithAlternateEncoder(event_data.into_event()),\n            RawTestEvent::ResourceReject {\n                external_resource_rejects: event_data,\n            } => TestEvent::FailWithExternalResource(event_data.into_event()),\n        }\n    }\n}\n\npub fn encode_test_event(\n    encoder: &mut Encoder<encoding::Framer>,\n    buf: &mut BytesMut,\n    event: TestEvent,\n) {\n    match event {\n        TestEvent::Passthrough(event) | TestEvent::FailWithExternalResource(event) => {\n            // Encode the event normally.\n            encoder\n                .encode(event, buf)\n                .expect(\"should not fail to encode input event\");\n        }\n        TestEvent::FailWithAlternateEncoder(event) => {\n            // This is a little fragile, but we check what serializer this encoder uses, and based\n            // on `Serializer::supports_json`, we choose an opposing codec. For example, if the\n            // encoder supports JSON, we'll use a serializer that doesn't support JSON, and vise\n            // versa.\n            let mut alt_encoder = if encoder.serializer().supports_json() {\n                Encoder::<encoding::Framer>::new(\n                    LengthDelimitedEncoder::default().into(),\n                    LogfmtSerializer.into(),\n                )\n            } else {\n                Encoder::<encoding::Framer>::new(\n                    NewlineDelimitedEncoder::default().into(),\n                    JsonSerializer::new(\n                        MetricTagValues::default(),\n                        JsonSerializerOptions::default(),\n                    )","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/vectordotdev/vector/blob/bdb87aeaa4c4ff27c0ba643c1c77b21bf2ef4013/src/components/validation/resources/event.rs#L146-L182","documentation":"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.","triggerScenarios":"`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).","commonSituations":"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.","solutions":["Switch the validation test's encoder to one compatible with the test events (e.g. json codec)","Check the TestEvent payload for fields the chosen encoder can't represent and simplify it","Update Vector; if the default codec fails, report the failing serializer"],"exampleFix":"// before\n[components.test_event]\nencoder = { codec = \"avro\", schema = \"...\" }\n// after\n[components.test_event]\nencoder = { codec = \"json\" }","handlingStrategy":"validation","validationCode":"// Prefer codecs known to encode test events:\n// ensure encoder.codec in [\"json\",\"text\",\"ndjson\"] before running validation","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use standard codecs (json/text) in validation test cases","Avoid schema-strict encoders (Avro etc.) for generated test events","Check encoder docs for supported event types"],"tags":["rust","validation","encoding","codec"],"backgroundTag":"json-marshal-failed","analyzedSha":"bdb87aeaa4c4ff27c0ba643c1c77b21bf2ef4013","analyzedAt":"2026-09-16T02:53:35.741Z","contentChangedAt":"2026-09-16T02:53:35.741Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}