{"record":{"id":"178a880585bf103e","repo":"Pumpkin-MC/Pumpkin","slug":"invalid-compression-level","errorCode":null,"errorMessage":"Invalid compression Level","messagePattern":"Invalid compression Level","errorType":"exception","errorClass":"CompressionLevelError","httpStatus":null,"severity":"error","filePath":"crates/pumpkin-protocol/src/java/packet_encoder.rs","lineNumber":372,"sourceCode":"    let version_number = P::to_id(*version);\n    if version_number == -1 {\n        return Err(WritingError::UnsupportedVersion(*version));\n    }\n    write.write_var_int(&VarInt(version_number))?;\n    packet.write_packet_data(write, version)\n}\n\npub fn serialize_packet<P: ClientPacket + ?Sized>(\n    packet: &P,\n    version: &JavaMinecraftVersion,\n) -> Result<Bytes, WritingError> {\n    let mut packet_buf = Vec::new();\n    write_packet(packet, version, &mut packet_buf)?;\n    Ok(packet_buf.into())\n}\n\n#[derive(Error, Debug)]\n#[error(\"Invalid compression Level\")]\npub struct CompressionLevelError;\n\n#[cfg(test)]\nmod tests {\n    use std::io::Read;\n\n    use super::*;\n    use crate::java::client::status::CStatusResponse;\n    use crate::packet::MultiVersionJavaPacket;\n    use crate::ser::{NetworkReadExt, NetworkWriteExt};\n    use crate::{ClientPacket, ReadingError};\n    use aes::Aes128;\n    use cfb8::Decryptor as Cfb8Decryptor;\n    use flate2::read::ZlibDecoder;\n    use pumpkin_data::packet::clientbound::status::STATUS_RESPONSE;\n    use pumpkin_macros::java_packet;\n    use pumpkin_util::version::JavaMinecraftVersion;\n","sourceCodeStart":354,"sourceCodeEnd":390,"githubUrl":"https://github.com/Pumpkin-MC/Pumpkin/blob/8d4639e25a57c15e47448ec327c780d41bbf2356/crates/pumpkin-protocol/src/java/packet_encoder.rs#L354-L390","documentation":"`CompressionLevelError` is returned when a compression level outside the valid range (0-9 for zlib/deflate) is supplied to packet encoding configuration. It is a dedicated error type rather than an io::Error so callers can match on it specifically.","triggerScenarios":"Calling the packet encoder's compression setup (e.g. `enable_compression`/level setter) with a level below 0 or above 9, or from a config value parsed incorrectly.","commonSituations":"A typo'd or mis-scaled value in server configuration (e.g. 10 or 22 taken from another library's scale); copying a compression level from a different ecosystem with a different valid range.","solutions":["Set the compression level to an integer in 0-9 (0 = no compression, 9 = max).","Clamp or validate the level at config load time before handing it to the encoder.","Check the pumpkin server config file for a bad `compression_level` value."],"exampleFix":"// before\nencoder.set_compression_level(15)?;\n// after\nlet level = level.clamp(0, 9);\nencoder.set_compression_level(level)?;","handlingStrategy":"validation","validationCode":"fn validate_compression_level(level: i32) -> Result<u8, String> {\n    if (0..=9).contains(&level) { Ok(level as u8) } else { Err(format!(\"compression level {level} not in 0-9\")) }\n}","typeGuard":null,"tryCatchPattern":"match encoder.enable_compression(level) {\n    Ok(()) => {},\n    Err(e) if e.downcast_ref::<CompressionLevelError>().is_some() => {\n        eprintln!(\"bad compression level {level}, falling back to 6\");\n        encoder.enable_compression(6)?;\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Clamp config values to 0-9 at load time.","Document the valid range next to the config option.","Unit-test config parsing with boundary values."],"tags":["protocol","compression","configuration","zlib"],"backgroundTag":"invalid-config-value","analyzedSha":"8d4639e25a57c15e47448ec327c780d41bbf2356","analyzedAt":"2026-09-09T15:32:22.916Z","contentChangedAt":"2026-09-09T15:32:22.916Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}