quickwit-oss/tantivy · error
expecting a Term with a json type and json path
Error message
expecting a Term with a json type and json path
What it means
Fires at the start of convert_to_fast_value_and_append_to_json_term, a helper that infers a JSON type (datetime, number, bool) from a string and appends it to a term. Per its contract, the incoming term must be a JSON term that already carries a JSON path but no value bytes yet; as_json_value_bytes() returns None if the term is not a JSON-type term at all. The panic therefore reports a caller passing a term built for a non-JSON field type or without a JSON path.
Source
Thrown at src/core/json_utils.rs:274
ctx,
positions_per_path,
);
}
}
}
/// Tries to infer a JSON type from a string and append it to the term.
///
/// The term must be json + JSON path.
pub fn convert_to_fast_value_and_append_to_json_term(
term: &Term,
text: &str,
truncate_date_for_search: bool,
) -> Option<Term> {
assert_eq!(
term.value()
.as_json_value_bytes()
.expect("expecting a Term with a json type and json path")
.as_serialized()
.len(),
0,
"JSON value bytes should be empty"
);
try_convert_to_datetime_and_append_to_json_term(term, text, truncate_date_for_search)
.or_else(|| try_convert_to_number_and_append_to_json_term(term, text))
.or_else(|| try_convert_to_bool_and_append_to_json_term_typed(term, text))
}
fn try_convert_to_datetime_and_append_to_json_term(
term: &Term,
text: &str,
truncate_date_for_search: bool,
) -> Option<Term> {
let dt = OffsetDateTime::parse(text, &Rfc3339).ok()?;
let mut dt = DateTime::from_utc(dt.to_offset(UtcOffset::UTC));
if truncate_date_for_search {View on GitHub (pinned to b5d8deb80c)
Solutions
- Only call this helper with terms constructed via Term::from_field_json / json path APIs
- Check callers like compute_boundary_term and generate_literals_for_json_object build the term with the json type and path set
- Add a typed wrapper (e.g. take JsonTerm) to make the precondition explicit
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at src/core/json_utils.rs:274 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of quickwit-oss/tantivy@b5d8deb80c (2026-09-05).
Data as JSON: /api/errors/b371233b623bf339.
Report an issue: GitHub.