{"record":{"id":"2f2ddccf3feca0b3","repo":"phacility/phabricator","slug":"specify-a-numeric-threshold-between-0-and-1","errorCode":null,"errorMessage":"Specify a numeric threshold between 0 and 1.","messagePattern":"Specify a numeric threshold between 0 and 1\\.","errorType":"console","errorClass":"PhutilArgumentUsageException","httpStatus":null,"severity":"warning","filePath":"src/applications/search/management/PhabricatorSearchManagementNgramsWorkflow.php","lineNumber":47,"sourceCode":"  public function execute(PhutilArgumentParser $args) {\n    $min_documents = 4096;\n\n    $is_reset = $args->getArg('reset');\n    $threshold = $args->getArg('threshold');\n\n    if ($is_reset && $threshold !== null) {\n      throw new PhutilArgumentUsageException(\n        pht('Specify either --reset or --threshold, not both.'));\n    }\n\n    if (!$is_reset && $threshold === null) {\n      throw new PhutilArgumentUsageException(\n        pht('Specify either --reset or --threshold.'));\n    }\n\n    if (!$is_reset) {\n      if (!is_numeric($threshold)) {\n        throw new PhutilArgumentUsageException(\n          pht('Specify a numeric threshold between 0 and 1.'));\n      }\n\n      $threshold = (double)$threshold;\n      if ($threshold <= 0 || $threshold >= 1) {\n        throw new PhutilArgumentUsageException(\n          pht('Threshold must be greater than 0.0 and less than 1.0.'));\n      }\n    }\n\n    $all_objects = id(new PhutilClassMapQuery())\n      ->setAncestorClass('PhabricatorFerretInterface')\n      ->execute();\n\n    foreach ($all_objects as $object) {\n      $engine = $object->newFerretEngine();\n      $conn = $object->establishConnection('w');\n      $display_name = get_class($object);","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/search/management/PhabricatorSearchManagementNgramsWorkflow.php#L29-L65","documentation":"When --threshold is given to `bin/search ngrams`, is_numeric() is applied before the value is cast to double and used as a document-frequency fraction. Any non-null value failing is_numeric (empty string, 'auto', '50%', '1e', arrays) triggers this usage exception before any database work starts.","triggerScenarios":"`bin/search ngrams --threshold auto`, `--threshold 5%`, `--threshold ,5` (locale-typo), or shell quoting that injects stray characters.","commonSituations":"Passing percentages with a % suffix; locale/format confusion (comma decimal separator); quoting mistakes in scripts.","solutions":["Pass a bare decimal fraction: `--threshold 0.05`","Remove units like % - the value is a ratio, not a percentage","Quote the argument to keep the shell from mangling it"],"exampleFix":"# before\nbin/search ngrams --threshold 5%\n\n# after\nbin/search ngrams --threshold 0.05","handlingStrategy":"validation","validationCode":"if (!is_numeric($threshold)) {\n  // reject before invoking: threshold must be a plain decimal fraction\n}","typeGuard":"function isValidNgramThreshold($t) {\n  return is_numeric($t) && (double)$t > 0.0 && (double)$t < 1.0;\n}","tryCatchPattern":null,"preventionTips":["Pass bare decimals like 0.05; never percentages or words","Quote CLI values to avoid shell mangling","Validate numeric CLI inputs in wrapper scripts before shelling out"],"tags":["cli","ngrams","usage-error","numeric-validation"],"backgroundTag":"invalid-numeric-argument","analyzedSha":"5720a38cfe95b00ca4be5016dd0d2f3195f4fa04","analyzedAt":"2026-08-21T05:07:25.672Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}