quickwit-oss/tantivy · info

JSON serialization for IndexMeta should never fail.

Error message

JSON serialization for IndexMeta should never fail.

What it means

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.

Source

Thrown at src/index/index_meta.rs:402

        }
    }

    pub(crate) fn deserialize(
        meta_json: &str,
        inventory: &SegmentMetaInventory,
    ) -> serde_json::Result<IndexMeta> {
        let untracked_meta_json: UntrackedIndexMeta = serde_json::from_str(meta_json)?;
        Ok(untracked_meta_json.track(inventory))
    }
}

impl fmt::Debug for IndexMeta {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(
            f,
            "{}",
            serde_json::ser::to_string(self)
                .expect("JSON serialization for IndexMeta should never fail.")
        )
    }
}

#[cfg(test)]
mod tests {

    use super::IndexMeta;
    use crate::index::index_meta::UntrackedIndexMeta;
    use crate::schema::{Schema, TEXT};
    use crate::store::Compressor;
    #[cfg(feature = "zstd-compression")]
    use crate::store::ZstdCompressor;
    use crate::{IndexSettings, IndexSortByField, Order};

    #[test]
    fn test_serialize_metas() {
        let schema = {

View on GitHub (pinned to b5d8deb80c)

Solutions

  1. Report this as a bug to tantivy with the panic backtrace — it indicates an invariant violation.
  2. Check your tantivy version for known serialization bugs and upgrade.
  3. Avoid relying on Debug for IndexMeta; use the public fields or serde_json::to_string manually with error handling.

Example fix

// before
println!("{:?}", meta); // panics on serialization failure
// after
if let Ok(s) = serde_json::to_string(&meta) { println!("{}", s); }
Defensive patterns

Strategy: try-catch

Validate before calling

null

Type guard

null

Try / catch

match serde_json::ser::to_string(&meta) {
    Ok(s) => println!("{}", s),
    Err(e) => eprintln!("meta serialization failed: {e}"),
}

Prevention

When it happens

Trigger: 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).

Common situations: Debugging an IndexMeta after a tantivy version change; embedding IndexMeta in custom structs with conflicting serde derives.

Related errors


AI-assisted analysis of quickwit-oss/tantivy@b5d8deb80c (2026-09-05). Data as JSON: /api/errors/a19889c71d1e1ac0. Report an issue: GitHub.