{"record":{"id":"b371233b623bf339","repo":"quickwit-oss/tantivy","slug":"expecting-a-term-with-a-json-type-and-json-path","errorCode":null,"errorMessage":"expecting a Term with a json type and json path","messagePattern":"expecting a Term with a json type and json path","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/core/json_utils.rs","lineNumber":274,"sourceCode":"                ctx,\n                positions_per_path,\n            );\n        }\n    }\n}\n\n/// Tries to infer a JSON type from a string and append it to the term.\n///\n/// The term must be json + JSON path.\npub fn convert_to_fast_value_and_append_to_json_term(\n    term: &Term,\n    text: &str,\n    truncate_date_for_search: bool,\n) -> Option<Term> {\n    assert_eq!(\n        term.value()\n            .as_json_value_bytes()\n            .expect(\"expecting a Term with a json type and json path\")\n            .as_serialized()\n            .len(),\n        0,\n        \"JSON value bytes should be empty\"\n    );\n    try_convert_to_datetime_and_append_to_json_term(term, text, truncate_date_for_search)\n        .or_else(|| try_convert_to_number_and_append_to_json_term(term, text))\n        .or_else(|| try_convert_to_bool_and_append_to_json_term_typed(term, text))\n}\n\nfn try_convert_to_datetime_and_append_to_json_term(\n    term: &Term,\n    text: &str,\n    truncate_date_for_search: bool,\n) -> Option<Term> {\n    let dt = OffsetDateTime::parse(text, &Rfc3339).ok()?;\n    let mut dt = DateTime::from_utc(dt.to_offset(UtcOffset::UTC));\n    if truncate_date_for_search {","sourceCodeStart":256,"sourceCodeEnd":292,"githubUrl":"https://github.com/quickwit-oss/tantivy/blob/b5d8deb80c26924e6b007a5b1a7630f35ca64de4/src/core/json_utils.rs#L256-L292","documentation":"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.","triggerScenarios":"Thrown at src/core/json_utils.rs:274 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","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"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}