{"record":{"id":"ce5c72d837d4c3a7","repo":"alibaba/open-code-review","slug":"max-tools-must-be-a-non-negative-integer-0-mean","errorCode":null,"errorMessage":"--max-tools must be a non-negative integer (0 means use template default)","messagePattern":"--max-tools must be a non-negative integer \\(0 means use template default\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/opencodereview/shared_flags.go","lineNumber":141,"sourceCode":"\nfunc validateReviewOptions(opts *reviewOptions) error {\n\tif err := validateDiffMode(opts.from, opts.to, opts.commit); err != nil {\n\t\treturn err\n\t}\n\tif opts.preview && opts.resume != \"\" {\n\t\treturn fmt.Errorf(\"--preview and --resume cannot be used together\")\n\t}\n\tif err := validateAudience(opts.audience); err != nil {\n\t\treturn err\n\t}\n\tnormalizedFormat, err := validateOutputFormat(opts.outputFormat)\n\tif err != nil {\n\t\treturn err\n\t}\n\topts.outputFormat = normalizedFormat\n\tconst minMaxTools = 50\n\tif opts.maxTools < 0 {\n\t\treturn fmt.Errorf(\"--max-tools must be a non-negative integer (0 means use template default)\")\n\t}\n\tif opts.maxTools > 0 && opts.maxTools < minMaxTools {\n\t\tfmt.Fprintf(os.Stderr, \"[ocr] --max-tools %d is below minimum %d, using %d\\n\", opts.maxTools, minMaxTools, minMaxTools)\n\t\topts.maxTools = minMaxTools\n\t}\n\tif opts.maxGitProcs < 0 {\n\t\treturn fmt.Errorf(\"--max-git-procs must be a non-negative integer (0 means use default 16)\")\n\t}\n\tif opts.maxTokens < 0 {\n\t\treturn fmt.Errorf(\"--max-tokens must be a non-negative integer (0 means use configured or template default)\")\n\t}\n\tif opts.maxTokensBudget < 0 {\n\t\treturn fmt.Errorf(\"--max-tokens-budget must be a non-negative integer (0 means unlimited)\")\n\t}\n\tif opts.effort != \"\" {\n\t\tif _, err := template.ParseEffort(opts.effort); err != nil {\n\t\t\treturn fmt.Errorf(\"--effort: %w\", err)\n\t\t}","sourceCodeStart":123,"sourceCodeEnd":159,"githubUrl":"https://github.com/alibaba/open-code-review/blob/5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f/cmd/opencodereview/shared_flags.go#L123-L159","documentation":"validateReviewOptions requires --max-tools to be >= 0; 0 is allowed and means 'use the template default'. Negative values are rejected. Additionally, a positive value below the minimum of 50 is not an error but is clamped up to 50 with a stderr notice.","triggerScenarios":"Passing --max-tools -1 (or any negative number) to review — the opts.maxTools < 0 branch in validateReviewOptions, invoked from the review command's anonymous caller.","commonSituations":"Scripts computing the value via arithmetic that can go negative (e.g. $(($BUDGET - $USED))); config files with placeholder negatives; misunderstanding 0 as 'disable' when it actually means 'default'.","solutions":["Pass a non-negative integer: --max-tools 0 to use the template default","Clamp in your script: MAX_TOOLS=$(( value < 0 ? 0 : value ))","Fix the calculation producing the negative budget","Omit the flag entirely to get the default"],"exampleFix":"// before\nocr review --from main --to HEAD --max-tools -5\n// after\nocr review --from main --to HEAD --max-tools 0   # 0 = template default","handlingStrategy":"validation","validationCode":"case \"$MAX_TOOLS\" in ''|*[!0-9]*) echo \"max-tools must be a non-negative integer, got: $MAX_TOOLS\"; exit 2;; esac","typeGuard":"function isNonNegativeInt(v) { return Number.isInteger(v) && v >= 0; }","tryCatchPattern":"ocr review --max-tools \"$MAX_TOOLS\" 2>err.log || { grep -q 'max-tools must be a non-negative' err.log && ocr review --max-tools 0; }","preventionTips":["Clamp computed budgets: v < 0 ? 0 : v","Remember 0 means 'template default', not 'disabled'","Validate config files that feed numeric flags","Note values 1-49 are silently raised to 50 with a stderr warning"],"tags":["cli","flags","validation","numeric"],"backgroundTag":"invalid-numeric-argument","analyzedSha":"5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f","analyzedAt":"2026-09-02T02:08:09.116Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}