{"record":{"id":"4cbc64f470d6e1f0","repo":"quickwit-oss/tantivy","slug":"invalid-value-type-id-num","errorCode":null,"errorMessage":"Invalid value type id: {num}","messagePattern":"Invalid value type id: (.+?)","errorType":"exception","errorClass":"io::Error","httpStatus":null,"severity":"error","filePath":"src/schema/document/default_document.rs","lineNumber":573,"sourceCode":"    Object = 11,\n    /// Pre-tokenized str type,\n    Array = 12,\n    /// Opaque payload of a plugin-defined custom field.\n    Custom = 13,\n}\n\nimpl BinarySerializable for ValueType {\n    fn serialize<W: Write + ?Sized>(&self, writer: &mut W) -> io::Result<()> {\n        (*self as u8).serialize(writer)?;\n        Ok(())\n    }\n\n    fn deserialize<R: Read>(reader: &mut R) -> io::Result<Self> {\n        let num = u8::deserialize(reader)?;\n        let type_id = if (0..=13).contains(&num) {\n            unsafe { std::mem::transmute::<u8, ValueType>(num) }\n        } else {\n            return Err(io::Error::new(\n                io::ErrorKind::InvalidData,\n                format!(\"Invalid value type id: {num}\"),\n            ));\n        };\n        Ok(type_id)\n    }\n}\n\nimpl<'a, V: Value<'a>> From<&ReferenceValue<'a, V>> for ValueType {\n    fn from(value: &ReferenceValue<'a, V>) -> Self {\n        match value {\n            ReferenceValue::Leaf(leaf) => leaf.into(),\n            ReferenceValue::Array(_) => ValueType::Array,\n            ReferenceValue::Object(_) => ValueType::Object,\n        }\n    }\n}\nimpl<'a> From<&ReferenceValueLeaf<'a>> for ValueType {","sourceCodeStart":555,"sourceCodeEnd":591,"githubUrl":"https://github.com/quickwit-oss/tantivy/blob/b5d8deb80c26924e6b007a5b1a7630f35ca64de4/src/schema/document/default_document.rs#L555-L591","documentation":"DefaultDocument's Deserialize impl reads a u8 type id and transmutes it to ValueType, but only for ids 0..=13 which are the valid discriminants. Any other byte cannot be a ValueType, so the unsafe transmute is guarded and this InvalidData error is returned instead of producing a bogus enum value.","triggerScenarios":"deserialize on a document stream whose ValueType tag byte is > 13: corrupted stored/quickwit documents, data written by a newer version with additional ValueTypes, or hand-built byte fixtures with a wrong tag.","commonSituations":"Cross-version index reads (newer writer, older reader); bit corruption in stored documents; tests or fixtures encoding Value types with incorrect numeric ids.","solutions":["Upgrade tantivy to the writer's version so new type ids are understood","Re-index or restore the corrupted document/file from a backup","When crafting serialized Values in tests, use a valid type id in 0..=13 (prefer the enum's serialized form, not a raw number)","Enable checksummed storage or validate files to catch corruption earlier"],"exampleFix":"// before (hand-crafted fixture)\nbytes.push(42u8); // invalid type id -> \"Invalid value type id: 42\"\n// after\nbytes.push(ValueType::Str as u8); // a valid, in-range type id","handlingStrategy":"type-guard","validationCode":"fn is_valid_value_type_id(b: u8) -> bool { b <= 13 }","typeGuard":"fn valid_value_type_id(b: u8) -> Option<u8> {\n    (b <= 13).then_some(b)\n}","tryCatchPattern":"match deserialize_result {\n    Err(e) if e.to_string().contains(\"Invalid value type id\") => {\n        eprintln!(\"corrupt or newer-format document; restore/re-index\");\n    }\n    Err(e) => return Err(e),\n    Ok(v) => v,\n}","preventionTips":["Keep reader version aligned with the writer's tantivy version","Use ValueType serialization APIs instead of raw numeric ids in fixtures","Add checksums on stored documents to catch corruption early","Verify data integrity after copying/downloading index files"],"tags":["deserialization","schema","invalid-data","corrupt-data"],"backgroundTag":"unknown-field-type-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"}