{"record":{"id":"a19889c71d1e1ac0","repo":"quickwit-oss/tantivy","slug":"json-serialization-for-indexmeta-should-never-fail","errorCode":null,"errorMessage":"JSON serialization for IndexMeta should never fail.","messagePattern":"JSON serialization for IndexMeta should never fail\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"info","filePath":"src/index/index_meta.rs","lineNumber":402,"sourceCode":"        }\n    }\n\n    pub(crate) fn deserialize(\n        meta_json: &str,\n        inventory: &SegmentMetaInventory,\n    ) -> serde_json::Result<IndexMeta> {\n        let untracked_meta_json: UntrackedIndexMeta = serde_json::from_str(meta_json)?;\n        Ok(untracked_meta_json.track(inventory))\n    }\n}\n\nimpl fmt::Debug for IndexMeta {\n    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {\n        write!(\n            f,\n            \"{}\",\n            serde_json::ser::to_string(self)\n                .expect(\"JSON serialization for IndexMeta should never fail.\")\n        )\n    }\n}\n\n#[cfg(test)]\nmod tests {\n\n    use super::IndexMeta;\n    use crate::index::index_meta::UntrackedIndexMeta;\n    use crate::schema::{Schema, TEXT};\n    use crate::store::Compressor;\n    #[cfg(feature = \"zstd-compression\")]\n    use crate::store::ZstdCompressor;\n    use crate::{IndexSettings, IndexSortByField, Order};\n\n    #[test]\n    fn test_serialize_metas() {\n        let schema = {","sourceCodeStart":384,"sourceCodeEnd":420,"githubUrl":"https://github.com/quickwit-oss/tantivy/blob/b5d8deb80c26924e6b007a5b1a7630f35ca64de4/src/index/index_meta.rs#L384-L420","documentation":"IndexMeta's Debug implementation serializes itself to JSON and unwraps the result with expect(). Since IndexMeta only contains serializable primitives and enums, serialization is expected to always succeed; a panic here means the internal data structure is in a state serde_json cannot encode.","triggerScenarios":"Calling format!(\"{:?}\", index_meta) or {:?} logging/println on an IndexMeta whose fields fail serde_json serialization (theoretically never, unless custom serde impls or version changes introduce non-serializable state).","commonSituations":"Debugging an IndexMeta after a tantivy version change; embedding IndexMeta in custom structs with conflicting serde derives.","solutions":["Report this as a bug to tantivy with the panic backtrace — it indicates an invariant violation.","Check your tantivy version for known serialization bugs and upgrade.","Avoid relying on Debug for IndexMeta; use the public fields or serde_json::to_string manually with error handling."],"exampleFix":"// before\nprintln!(\"{:?}\", meta); // panics on serialization failure\n// after\nif let Ok(s) = serde_json::to_string(&meta) { println!(\"{}\", s); }","handlingStrategy":"try-catch","validationCode":"null","typeGuard":"null","tryCatchPattern":"match serde_json::ser::to_string(&meta) {\n    Ok(s) => println!(\"{}\", s),\n    Err(e) => eprintln!(\"meta serialization failed: {e}\"),\n}","preventionTips":["Prefer manual serde_json::to_string with error handling over Debug formatting","Pin and test your tantivy version when upgrading","Report the panic upstream with the IndexMeta contents if it occurs","Do not add non-serializable state via wrappers around IndexMeta"],"tags":["rust","panic","serialization","serde","debug"],"backgroundTag":"serialization-failed","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"}