{"record":{"id":"6539357131418dd3","repo":"quickwit-oss/quickwit","slug":"the-user-query-should-be-valid","errorCode":null,"errorMessage":"The user query should be valid.","messagePattern":"The user query should be valid\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"quickwit/quickwit-query/src/query_ast/mod.rs","lineNumber":325,"sourceCode":"/// The resolution assumes that there are no default search fields\n/// in the doc mapper.\n///\n/// # Panics\n///\n/// Panics if the user text is invalid.\npub fn qast_json_helper(user_text: &str, default_fields: &[&'static str]) -> String {\n    let ast = qast_helper(user_text, default_fields);\n    serde_json::to_string(&ast).expect(\"The query AST should be JSON serializable.\")\n}\n\npub fn qast_helper(user_text: &str, default_fields: &[&'static str]) -> QueryAst {\n    let default_fields: Vec<String> = default_fields\n        .iter()\n        .map(|default_field| default_field.to_string())\n        .collect();\n    query_ast_from_user_text(user_text, Some(default_fields))\n        .parse_user_query(&[])\n        .expect(\"The user query should be valid.\")\n}\n\n/// Creates a QueryAST with a single UserInputQuery node.\n///\n/// Disclaimer:\n/// At this point the query has not been parsed.\n///\n/// The actual parsing is meant to happen on a root node,\n/// `default_fields` can be passed to decide which field should be search\n/// if not specified specifically in the user query (e.g. hello as opposed to \"body:hello\").\n///\n/// If it is not supplied, the docmapper search fields are meant to be used.\n///\n/// If no boolean operator is specified, the default is `AND` (contrary to the Elasticsearch\n/// default).\npub fn query_ast_from_user_text(user_text: &str, default_fields: Option<Vec<String>>) -> QueryAst {\n    UserInputQuery {\n        user_text: user_text.to_string(),","sourceCodeStart":307,"sourceCodeEnd":343,"githubUrl":"https://github.com/quickwit-oss/quickwit/blob/a39730c5cdcd1a4fe798403737ae293999ea21f8/quickwit/quickwit-query/src/query_ast/mod.rs#L307-L343","documentation":"qast_helper converts user query text into a parsed QueryAST and asserts the query is valid with .expect(\"The user query should be valid.\"). It's a convenience/test helper: if query_ast_from_user_text(...).parse_user_query(&[]) returns an error (invalid query syntax, unknown field, bad aggregation, etc.) the helper panics instead of returning the error. Callers such as DeleteQuery parsing and qast_json_helper rely on it.","triggerScenarios":"Passing user_text that fails parse_user_query: malformed query DSL syntax (e.g. unbalanced quotes/parentheses), invalid field names/types, unsupported aggregation or sort field, or an empty/invalid query string reaching DeleteQuery parsing or qast_json_helper.","commonSituations":"Sending a delete query with bad syntax through the REST/gRPC delete API; programmatically building query ASTs with hand-written JSON that references nonexistent or mistyped fields; upgrading quickwit where a previously valid query syntax is now rejected.","solutions":["Fix the query text: validate syntax and field names against the index schema before calling the API.","If this is your own code path, replace the expect with proper error propagation (return anyhow::Result) so callers get a descriptive 400-style error instead of a panic.","For DeleteQuery flows, test the query with a search first to confirm it parses against your index configuration (default fields, schemas)."],"exampleFix":"// before\nquery_ast_from_user_text(user_text, Some(default_fields))\n    .parse_user_query(&[])\n    .expect(\"The user query should be valid.\")\n// after\nquery_ast_from_user_text(user_text, Some(default_fields))\n    .parse_user_query(&[])\n    .context(\"invalid user query\")?","handlingStrategy":"try-catch","validationCode":"// validate before submitting\ndef search_query_ok(q: str) -> bool: return bool(q.strip()) and q.count('\"') % 2 == 0 and q.count('(') == q.count(')')","typeGuard":null,"tryCatchPattern":"// Rust helper usage\nmatch query_ast_from_user_text(user_text, Some(default_fields)).parse_user_query(&[]) {\n    Ok(qast) => qast,\n    Err(e) => return Err(anyhow::anyhow!(\"invalid user query: {e}\")),\n}","preventionTips":["Validate query text against the index schema (field names, types) before parsing.","Test delete/JSON queries with a search request first.","Avoid expect in helpers reachable from user input; propagate errors instead."],"tags":["rust","query-parsing","panic","user-input"],"backgroundTag":"invalid-query-parameter","analyzedSha":"a39730c5cdcd1a4fe798403737ae293999ea21f8","analyzedAt":"2026-09-08T13:19:37.784Z","contentChangedAt":"2026-09-08T13:19:37.784Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}