{"record":{"id":"f4a605cbf37321ab","repo":"quickwit-oss/tantivy","slug":"invaliddata-f4a605","errorCode":"InvalidData","errorMessage":"Unknown code `{code}.`","messagePattern":"Unknown code `(.+?)\\.`","errorType":"error_code","errorClass":"io::Error","httpStatus":null,"severity":"error","filePath":"columnar/src/column_values/u128_based/mod.rs","lineNumber":84,"sourceCode":"\n#[derive(PartialEq, Eq, PartialOrd, Ord, Debug, Clone, Copy)]\n#[repr(u8)]\n/// Available codecs to use to encode the u128 (via [`MonotonicallyMappableToU128`]) converted data.\npub(crate) enum U128FastFieldCodecType {\n    /// This codec takes a large number space (u128) and reduces it to a compact number space, by\n    /// removing the holes.\n    CompactSpace = 1,\n}\n\nimpl BinarySerializable for U128FastFieldCodecType {\n    fn serialize<W: Write + ?Sized>(&self, wrt: &mut W) -> io::Result<()> {\n        self.to_code().serialize(wrt)\n    }\n\n    fn deserialize<R: io::Read>(reader: &mut R) -> io::Result<Self> {\n        let code = u8::deserialize(reader)?;\n        let codec_type: Self = Self::from_code(code)\n            .ok_or_else(|| io::Error::new(io::ErrorKind::InvalidData, \"Unknown code `{code}.`\"))?;\n        Ok(codec_type)\n    }\n}\n\nimpl U128FastFieldCodecType {\n    pub(crate) fn to_code(self) -> u8 {\n        self as u8\n    }\n\n    pub(crate) fn from_code(code: u8) -> Option<Self> {\n        match code {\n            1 => Some(Self::CompactSpace),\n            _ => None,\n        }\n    }\n}\n\n/// Returns the correct codec reader wrapped in the `Arc` for the data.","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/quickwit-oss/tantivy/blob/b5d8deb80c26924e6b007a5b1a7630f35ca64de4/columnar/src/column_values/u128_based/mod.rs#L66-L102","documentation":"U128FastFieldCodec::deserialize reads a one-byte codec type code and maps it back via from_code; an unrecognized byte yields InvalidData with this message. Note the message literally contains backticks around `{code}.` — the format string was never interpolated, so the byte value is not shown. It signals reading data written with an unknown/newer codec type or corruption.","triggerScenarios":"Deserializing a u128 fast field whose codec code byte is not among the known from_code values — e.g. index written by a newer tantivy with a new codec, byte misalignment, or corrupted files.","commonSituations":"Cross-version index reads (new writer, old reader); damaged segment files; manually edited or partially written columnar data.","solutions":["Use a tantivy version at least as new as the one that wrote the index.","Rebuild the segment/index with the current version.","Check for corruption — validate the byte stream alignment before the codec code.","Patch from_code if adding a custom codec type so the code round-trips."],"exampleFix":"// before\nlet codec = CodecType::deserialize(&mut reader)?; // InvalidData on unknown code\n// after\n// ensure the writer's tantivy version is supported before opening the index,\n// or map the raw code yourself:\nlet code = u8::deserialize(&mut reader)?;\nlet codec = CodecType::from_code(code)\n    .ok_or_else(|| format!(\"unsupported codec code {code}\").into())?;","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"fn is_known_codec_code(code: u8) -> bool {\n    CodecType::from_code(code).is_some()\n}","tryCatchPattern":"match CodecType::deserialize(&mut reader) {\n    Err(e) if e.kind() == std::io::ErrorKind::InvalidData\n        && e.to_string().starts_with(\"Unknown code\") => {\n        // index written by newer tantivy or corrupt: upgrade reader or rebuild\n    }\n    other => other?,\n}","preventionTips":["Match the reader's tantivy version to the writer's before opening indexes.","Round-trip custom codec to_code/from_code mappings in tests.","Validate segment files for corruption before deserialization.","Fail fast with the raw byte value in your own reader wrapper since the library message doesn't interpolate the code."],"tags":["io","codec","deserialization","version-mismatch"],"backgroundTag":"unknown-codec-code","analyzedSha":"b5d8deb80c26924e6b007a5b1a7630f35ca64de4","analyzedAt":"2026-09-05T13:20:51.521Z","contentChangedAt":"2026-09-05T13:20:51.521Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}