{"record":{"id":"13d4ccdc1a1cbd9d","repo":"vectordotdev/vector","slug":"building-serializer-should-never-fail","errorCode":null,"errorMessage":"building serializer should never fail","messagePattern":"building serializer should never fail","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/components/validation/resources/mod.rs","lineNumber":92,"sourceCode":"    ///\n    /// The encoder is generated as an inverse to the input codec: if a decoding configuration was\n    /// given, we generate an encoder that satisfies that decoding configuration, and vice versa.\n    pub fn into_encoder(&self) -> Encoder<encoding::Framer> {\n        let (framer, serializer) = match self {\n            Self::Encoding(config) => (\n                Framer::Bytes(BytesEncoder),\n                config.build().expect(\"should not fail to build serializer\"),\n            ),\n            Self::EncodingWithFraming(config) => {\n                let (maybe_framing, serializer) = config.config();\n                (\n                    maybe_framing\n                        .clone()\n                        .unwrap_or(FramingConfig::Bytes)\n                        .build(),\n                    serializer\n                        .build()\n                        .expect(\"building serializer should never fail\"),\n                )\n            }\n            Self::Decoding(config) => (\n                decoder_framing_to_encoding_framer(config.framing()),\n                deserializer_config_to_serializer(config.config()),\n            ),\n        };\n\n        Encoder::<encoding::Framer>::new(framer, serializer)\n    }\n\n    /// Gets a decoder for this codec.\n    ///\n    /// The decoder is generated as an inverse to the input codec: if an encoding configuration was\n    /// given, we generate a decoder that satisfies that encoding configuration, and vice versa.\n    pub fn into_decoder(&self, log_namespace: LogNamespace) -> vector_lib::Result<Decoder> {\n        let (framer, deserializer) = match self {\n            Self::Decoding(config) => return config.build(),","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/vectordotdev/vector/blob/bdb87aeaa4c4ff27c0ba643c1c77b21bf2ef4013/src/components/validation/resources/mod.rs#L74-L110","documentation":"Same as the Encoding arm: for InputResource::EncodingWithFraming, into_encoder builds the framing and serializer from the codec config and expects both to succeed. A panic means the serializer half of an encoding-with-framing configuration failed to build despite being assumed pre-validated.","triggerScenarios":"spawn_input_http_server/spawn_input_http_client processes an EncodingWithFraming input whose SerializerConfig::build() returns Err at runtime.","commonSituations":"Invalid codec options (e.g. unsupported serializer settings) in a validation harness config; drift between codec config validation and build() requirements after a refactor.","solutions":["Run the serializer config through build() early in test setup to surface the real codec error.","Fix the encoding configuration used by the validation test so it satisfies codec constraints.","Replace the expect with a descriptive panic including the underlying error to speed diagnosis."],"exampleFix":"// before\nserializer.build().expect(\"building serializer should never fail\")\n// after\nserializer.build().unwrap_or_else(|e| panic!(\"serializer build failed: {e}\"))","handlingStrategy":"validation","validationCode":"// Check both halves of an EncodingWithFraming config early\nlet (framing, serializer) = config.config();\nframing.clone().unwrap_or(FramingConfig::Bytes).build().expect(\"bad framing\");\nserializer.build().expect(\"bad serializer\");","typeGuard":null,"tryCatchPattern":"serializer.build().unwrap_or_else(|e| panic!(\"encoding-with-framing serializer invalid: {e}\"))","preventionTips":["Pre-build framing and serializer configs in test setup to get real codec errors.","After codec crate updates, re-run validation harness smoke tests.","Avoid hand-rolled EncodingWithFraming configs; derive them from validated component configs."],"tags":["codec","serializer","framing","panic"],"backgroundTag":"internal-invariant-violation","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"}