{"record":{"id":"7113ab2ed97c3446","repo":"phacility/phabricator","slug":"query-contains-a-token-s-with-no-search-term","errorCode":null,"errorMessage":"Query contains a token (\"%s\") with no search term. Query tokens specify text to search for.","messagePattern":"Query contains a token \\(\"(.+?)\"\\) with no search term\\. Query tokens specify text to search for\\.","errorType":"validation","errorClass":"PhutilSearchQueryCompilerSyntaxException","httpStatus":null,"severity":"warning","filePath":"src/applications/search/compiler/PhutilSearchQueryCompiler.php","lineNumber":346,"sourceCode":"            } else {\n              $require_value = true;\n            }\n            break;\n          case self::OPERATOR_SUBSTRING:\n            if ($enable_functions && ($token['function'] !== null)) {\n              $operator = self::OPERATOR_PRESENT;\n              $value = null;\n            } else {\n              $require_value = true;\n            }\n            break;\n          default:\n            $require_value = true;\n            break;\n        }\n\n        if ($require_value) {\n          throw new PhutilSearchQueryCompilerSyntaxException(\n            pht(\n              'Query contains a token (\"%s\") with no search term. Query '.\n              'tokens specify text to search for.',\n              $this->getDisplayToken($token)));\n        }\n      }\n\n      $result = array(\n        'operator' => $operator,\n        'quoted' => $is_quoted,\n        'value' => $value,\n        'raw' => $this->getDisplayToken($token),\n      );\n\n      if ($enable_functions) {\n        // If a user provides a query like \"title:a b c\", we interpret all\n        // of the terms to be title terms: the \"title:\" function sticks\n        // until we encounter another function.","sourceCodeStart":328,"sourceCodeEnd":364,"githubUrl":"https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/search/compiler/PhutilSearchQueryCompiler.php#L328-L364","documentation":"After operator resolution a token ended up with an empty value while its operator requires text (require_value). Search tokens must specify something to search for; operators like a bare `+` or `-`, or a function prefix with no term (`title:`), produce a token whose value has zero length, which cannot compile into any meaningful query, so PhutilSearchQueryCompilerSyntaxException is thrown with the display form of the offending token.","triggerScenarios":"Queries like `cat +` or `cat -` (trailing operator with no term), `title:` with nothing after the colon, an empty quoted phrase `\"\"` where functions require a value, or a lone function name with functions enabled but no argument. Hit via UI search boxes, saved-query editing, or Conduit search parameters.","commonSituations":"Trailing space plus operator at the end of a query left over from deleting a word (`fix -` after removing the excluded term); copy-pasted queries where the term after an operator got dropped; programmatic query builders appending an operator prefix then an empty string term.","solutions":["Remove the dangling operator or add the missing term: `cat -` -> `cat`, `title:` -> `title:ship`.","When generating queries in code, skip emission whenever the term is empty: if ($term === '') continue; before prefixing operators.","Trim the query before submit so accidental trailing operators from deleted words are caught by eye.","Treat the exception as form validation: catch PhutilSearchQueryCompilerSyntaxException and re-show the query form with the message; the token is named in the error."],"exampleFix":"// before: emits operator with empty term when filter empty\n$parts[] = ($negate ? '-' : '').$term;\n\n// after: skip empty terms entirely\nif ($term !== '') {\n  $parts[] = ($negate ? '-' : '').$term;\n}","handlingStrategy":"validation","validationCode":"// Drop operator-only fragments before submitting\n$fragments = preg_split('/\\s+/', trim($query));\n$fragments = array_filter($fragments, function ($f) { return trim($f, '+-:') !== ''; });\n$query = implode(' ', $fragments);","typeGuard":"function hasNoEmptyTokens($q) { return !preg_match('/(^|\\s)[+-]+(:\\w+)?(\\s|$)/', $q); }","tryCatchPattern":"try {\n  $compiled = $compiler->compileQuery($field, $query);\n} catch (PhutilSearchQueryCompilerSyntaxException $ex) {\n  $e_query = $ex->getMessage(); // AphrontFormView error binding pattern\n}","preventionTips":["Trim queries before compile so trailing 'x -' style debris is caught by eye","Skip empty terms in generated queries","Bind the exception message to the query form field so users see which token failed"],"tags":["phabricator","search","query-syntax","empty-token","validation"],"backgroundTag":"empty-search-token","analyzedSha":"5720a38cfe95b00ca4be5016dd0d2f3195f4fa04","analyzedAt":"2026-08-21T05:07:25.672Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}