{"record":{"id":"256736f53b7546b7","repo":"databendlabs/databend","slug":"zip-type-requires-additional-judgment-and-use-com","errorCode":null,"errorMessage":"Zip type requires additional judgment and use `compress_all_zip`","messagePattern":"Zip type requires additional judgment and use `compress_all_zip`","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/common/compress/src/encode.rs","lineNumber":86,"sourceCode":"            }\n            CompressAlgorithm::Deflate => {\n                CompressCodec::Deflate(DeflateEncoder::new(Level::Default.into_flate2()))\n            }\n            CompressAlgorithm::Gzip => {\n                CompressCodec::Gzip(GzipEncoder::new(Level::Default.into_flate2()))\n            }\n            CompressAlgorithm::Lzma => {\n                CompressCodec::Lzma(LzmaEncoder::new(Level::Default.into_xz2()))\n            }\n            CompressAlgorithm::Xz => CompressCodec::Xz(XzEncoder::new(Level::Default.into_xz2())),\n            CompressAlgorithm::Zlib => {\n                CompressCodec::Zlib(ZlibEncoder::new(Level::Default.into_flate2()))\n            }\n            CompressAlgorithm::Zstd => {\n                CompressCodec::Zstd(ZstdEncoder::new(Level::Default.into_zstd()))\n            }\n            CompressAlgorithm::Zip => {\n                unreachable!(\"Zip type requires additional judgment and use `compress_all_zip`\")\n            }\n        }\n    }\n}\n\nimpl Encode for CompressCodec {\n    fn encode(\n        &mut self,\n        input: &mut PartialBuffer<impl AsRef<[u8]>>,\n        output: &mut PartialBuffer<impl AsRef<[u8]> + AsMut<[u8]>>,\n    ) -> Result<()> {\n        match self {\n            CompressCodec::Brotli(v) => v.encode(input, output),\n            CompressCodec::Bz2(v) => v.encode(input, output),\n            CompressCodec::Deflate(v) => v.encode(input, output),\n            CompressCodec::Gzip(v) => v.encode(input, output),\n            CompressCodec::Lzma(v) => v.encode(input, output),\n            CompressCodec::Xz(v) => v.encode(input, output),","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/databendlabs/databend/blob/288d84d76e20a2f8f7173bda9691eb6ece301aa9/src/common/compress/src/encode.rs#L68-L104","documentation":"The compression codec factory in src/common/compress cannot build a generic streaming encoder for the Zip algorithm, because ZIP is an archive format requiring per-entry bookkeeping, not a single-stream compressor. CompressAlgorithm::Zip therefore reaches an unreachable!() panic in CompressCodec::from; callers must use compress_all_zip instead.","triggerScenarios":"Constructing a CompressCodec via from() with CompressAlgorithm::Zip — e.g. a user-selected compression algorithm from stage/COPY options or API parameters is Zip while the generic encode path is invoked.","commonSituations":"Configuring compression=zip on an export/unload that uses stream-based encoding; an API caller picks Zip for a single-output writer; code refactoring dropped the special case that previously dispatched Zip to compress_all_zip.","solutions":["Dispatch Zip inputs to compress_all_zip before building a CompressCodec","Validate the configured compression algorithm up front and reject Zip on stream-based encoders","Use a supported single-stream algorithm (gzip, zstd, zstd_raw, etc.) when archive semantics are not required","Return a typed unsupported-algorithm error instead of panicking for clearer user feedback"],"exampleFix":"// before\nlet codec = CompressCodec::from(algorithm); // panics when algorithm == Zip\n// after\nlet out = match algorithm {\n    CompressAlgorithm::Zip => compress_all_zip(entries)?,\n    alg => CompressCodec::from(alg).encode(&data)?,\n};","handlingStrategy":"validation","validationCode":"if matches!(algorithm, CompressAlgorithm::Zip) {\n    return Err(ErrorCode::InvalidConfigValue(\n        \"compression\",\n        \"zip requires compress_all_zip; use gzip or zstd for stream output\",\n    ));\n}","typeGuard":"fn supports_stream_encode(alg: CompressAlgorithm) -> bool {\n    !matches!(alg, CompressAlgorithm::Zip)\n}","tryCatchPattern":"let out = if algorithm == CompressAlgorithm::Zip {\n    compress_all_zip(&entries)?\n} else {\n    CompressCodec::from(algorithm).encode(&data)?\n};","preventionTips":["Validate user/config compression options before encoding; reject Zip on streaming paths","Centralize algorithm dispatch in one function so Zip special-casing cannot be forgotten","Add a unit test asserting from() panics only for Zip and all other algorithms encode"],"tags":["compression","zip","panic","unsupported-algorithm"],"backgroundTag":"unsupported-operation","analyzedSha":"288d84d76e20a2f8f7173bda9691eb6ece301aa9","analyzedAt":"2026-09-11T11:29:36.208Z","contentChangedAt":"2026-09-11T11:29:36.208Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}