vectordotdev/vector · error

should not fail to build serializer

Error message

should not fail to build serializer

What it means

into_encoder builds the inverse encoder from a validation input's encoding configuration. The codec serializer config is expected to have been validated at config-parse time, so SerializerConfig::build() is unwrapped with an expect; a panic here means an encoding config reached runtime that the codec layer rejects (which the config validator should have caught).

Solutions

  1. Validate the serializer config via config.build() in test setup before calling into_encoder to get a real error message.
  2. Check which serializer option fails build() and correct the test's encoding configuration.
  3. If a codec constraint changed, update the validation resource configs to satisfy it (or add an early error path instead of expect).

Example fix

// before
config.build().expect("should not fail to build serializer")
// after
config.build().unwrap_or_else(|e| panic!("invalid serializer config: {e}"))
Defensive patterns

Strategy: validation

Validate before calling

// Pre-check the serializer config before it reaches the harness
let serializer = encoding_config.build()
    .expect("invalid serializer config in test setup");

Try / catch

match config.build() {
    Ok(s) => s,
    Err(e) => panic!("test encoding config invalid: {e}"),
}

Prevention

When it happens

Trigger: spawn_input_http_server or spawn_input_http_client calls into_encoder on an InputResource::Encoding whose SerializerConfig::build() returns Err — i.e. a serializer configuration invalid per codec rules slipped past validation.

Common situations: A newly added or mis-validated serializer option in a validation test harness; codec crate changes that tighten build() constraints without updating the validation resources code.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


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

Appendix: source

Thrown at src/components/validation/resources/mod.rs:81

    /// represent the data in a particular event type) so we must check at runtime to ensure that
    /// we're only generating event payloads that can be encoded/decoded for the given component.
    pub fn allowed_event_data_types(self) -> DataType {
        match self {
            Self::Encoding(encoding) => encoding.config().input_type(),
            Self::EncodingWithFraming(encoding) => encoding.config().1.input_type(),
            Self::Decoding(decoding) => decoding.config().output_type(),
        }
    }

    /// Gets an encoder for this codec.
    ///
    /// The encoder is generated as an inverse to the input codec: if a decoding configuration was
    /// given, we generate an encoder that satisfies that decoding configuration, and vice versa.
    pub fn into_encoder(&self) -> Encoder<encoding::Framer> {
        let (framer, serializer) = match self {
            Self::Encoding(config) => (
                Framer::Bytes(BytesEncoder),
                config.build().expect("should not fail to build serializer"),
            ),
            Self::EncodingWithFraming(config) => {
                let (maybe_framing, serializer) = config.config();
                (
                    maybe_framing
                        .clone()
                        .unwrap_or(FramingConfig::Bytes)
                        .build(),
                    serializer
                        .build()
                        .expect("building serializer should never fail"),
                )
            }
            Self::Decoding(config) => (
                decoder_framing_to_encoding_framer(config.framing()),
                deserializer_config_to_serializer(config.config()),
            ),
        };

View on GitHub (pinned to bdb87aeaa4)