{"record":{"id":"9b2b207b4a7b006f","repo":"vectordotdev/vector","slug":"zstd-encoder-should-not-fail-on-init-compressor","errorCode":null,"errorMessage":"Zstd encoder should not fail on init.","messagePattern":"Zstd encoder should not fail on init\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/sinks/util/compressor.rs","lineNumber":90,"sourceCode":"        match compression {\n            Compression::None => Writer::Plain(writer),\n            // Buffering writes to the underlying Encoder writer\n            // to avoid Vec-trashing and expensive memset syscalls.\n            // https://github.com/rust-lang/flate2-rs/issues/395#issuecomment-1975088152\n            Compression::Gzip(level) => Writer::Gzip(BufWriter::with_capacity(\n                GZIP_INPUT_BUFFER_CAPACITY,\n                GzEncoder::new(writer, level.as_flate2()),\n            )),\n            // Buffering writes to the underlying Encoder writer\n            // to avoid Vec-trashing and expensive memset syscalls.\n            // https://github.com/rust-lang/flate2-rs/issues/395#issuecomment-1975088152\n            Compression::Zlib(level) => Writer::Zlib(BufWriter::with_capacity(\n                ZLIB_INPUT_BUFFER_CAPACITY,\n                ZlibEncoder::new(writer, level.as_flate2()),\n            )),\n            Compression::Zstd(level) => {\n                let encoder = ZstdEncoder::new(writer, level.into())\n                    .expect(\"Zstd encoder should not fail on init.\");\n                Writer::Zstd(encoder)\n            }\n            Compression::Snappy => Writer::Snappy(SnappyEncoder::new(writer)),\n        }\n    }\n}\n\nimpl io::Write for Writer {\n    fn write(&mut self, buf: &[u8]) -> io::Result<usize> {\n        #[allow(clippy::disallowed_methods)] // Caller handles the result of `write`.\n        match self {\n            Writer::Plain(inner_buf) => inner_buf.write(buf),\n            Writer::Gzip(writer) => writer.write(buf),\n            Writer::Zlib(writer) => writer.write(buf),\n            Writer::Zstd(writer) => writer.write(buf),\n            Writer::Snappy(writer) => writer.write(buf),\n        }\n    }","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/vectordotdev/vector/blob/bdb87aeaa4c4ff27c0ba643c1c77b21bf2ef4013/src/sinks/util/compressor.rs#L72-L108","documentation":"This panic fires when constructing a `ZstdEncoder` in `Compressor::from` fails. Per the zstd crate, encoder initialization only fails on an invalid compression level or allocation failure; Vector guarantees the configured level is in the valid 1-22 range, so failure means the invariant is broken.","triggerScenarios":"Building a compressor with `Compression::Zstd(level)` where the mapped zstd level is outside the encoder's accepted range, or the allocator cannot provide memory for the encoder context.","commonSituations":"Essentially unreachable via normal config since Vector validates/normalizes zstd levels; could only appear under extreme memory pressure (OOM conditions) at sink construction.","solutions":["Report as a bug; this indicates an internal invariant about level validity was broken.","Verify the sink `compression: zstd` level configuration is a valid level (default/1-22).","Check host memory availability if this occurs at startup under heavy load."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Ensure the configured compression level is valid before building the compressor.\nassert!((1..=22).contains(&level), \"zstd level must be 1-22\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use default compression levels unless you have validated the range.","Watch for OOM conditions at sink startup on memory-constrained hosts.","Keep the zstd crate and Vector versions in sync with upstream releases."],"tags":["rust","compression","zstd","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"}