{"record":{"id":"295a09b61836e45b","repo":"quickwit-oss/quickwit","slug":"failed-to-parse-query","errorCode":null,"errorMessage":"failed to parse query: `{}`","messagePattern":"failed to parse query: `(.+?)`","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"quickwit/quickwit-query/src/query_ast/user_input_query.rs","lineNumber":66,"sourceCode":"\nimpl UserInputQuery {\n    /// Parse the user query to generate a structured QueryAST, without any UserInputQuery node.\n    ///\n    /// The `UserInputQuery` have an optional search_fields property that takes precedence over\n    /// the `default_search_fields`.\n    ///\n    /// In quickwit, the search fields in the `UserInputQuery` are usually supplied with the user\n    /// request.\n    /// The default_search_fields argument on the other hand, is the default search fields defined\n    /// in the `DocMapper`.\n    pub fn parse_user_query(&self, default_search_fields: &[String]) -> anyhow::Result<QueryAst> {\n        let search_fields = self\n            .default_fields\n            .as_ref()\n            .map(|search_fields| &search_fields[..])\n            .unwrap_or(default_search_fields);\n        let user_input_ast = tantivy::query_grammar::parse_query(&self.user_text)\n            .map_err(|_| anyhow::anyhow!(\"failed to parse query: `{}`\", &self.user_text))?;\n        let default_occur = match self.default_operator {\n            BooleanOperand::And => Occur::Must,\n            BooleanOperand::Or => Occur::Should,\n        };\n        convert_user_input_ast_to_query_ast(\n            user_input_ast,\n            default_occur,\n            search_fields,\n            self.lenient,\n        )\n    }\n}\n\nimpl From<UserInputQuery> for QueryAst {\n    fn from(user_text_query: UserInputQuery) -> Self {\n        QueryAst::UserInput(user_text_query)\n    }\n}","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/quickwit-oss/quickwit/blob/a39730c5cdcd1a4fe798403737ae293999ea21f8/quickwit/quickwit-query/src/query_ast/user_input_query.rs#L48-L84","documentation":"parse_user_query converts free-text user input into a query AST using tantivy's query grammar parser. This error is raised when the user_text fails tantivy::query_grammar::parse_query — meaning the query syntax itself is invalid (unbalanced quotes/parens, dangling operators, illegal syntax). The full offending query text is embedded in the message.","triggerScenarios":"Calling UserInputQuery::parse_user_query (via query AST conversion of a user-supplied query string) with text tantivy's grammar rejects: unbalanced quotes, unmatched parentheses, operators like AND/OR/NOT with no operands, or invalid field:value syntax.","commonSituations":"REST/gRPC clients sending raw user-typed search strings with stray characters; programmatic query builders interpolating values containing quotes or special chars; empty or operator-only query strings.","solutions":["Fix the query syntax: balance quotes and parentheses, ensure AND/OR/NOT have operands","Sanitize/escape user input before embedding it in the query string","Simplify to plain terms to isolate which token breaks parsing","If building queries programmatically, use the typed QueryAst API instead of string concatenation"],"exampleFix":"// before\nlet q = format!(\"field:{}\", user_input); // user_input = \"foo \"bar\"\"\n// after: escape quotes / use typed AST\nlet q = format!(\"field:{}\", escape_query_syntax(user_input));","handlingStrategy":"try-catch","validationCode":"fn query_parses(q: &str) -> bool { tantivy::query_grammar::parse_query(q).is_ok() }","typeGuard":null,"tryCatchPattern":"match parse_user_query(&query) {\n    Err(e) => {\n        // return 400 to the client with the invalid query text\n        Err(bad_request(format!(\"invalid query syntax: {e}\")))\n    }\n    Ok(ast) => Ok(ast),\n}","preventionTips":["Escape user input containing quotes, parens, and boolean keywords","Validate query strings client-side with a tantivy-compatible grammar","Use the structured QueryAst API for programmatic query construction"],"tags":["query-parsing","tantivy","user-input","query-dsl"],"backgroundTag":"invalid-argument-format","analyzedSha":"a39730c5cdcd1a4fe798403737ae293999ea21f8","analyzedAt":"2026-09-08T13:19:37.784Z","contentChangedAt":"2026-09-08T13:19:37.784Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}