{"record":{"id":"b5aa0d3b9754a319","repo":"alibaba/open-code-review","slug":"max-tokens-budget-must-be-a-non-negative-integer","errorCode":null,"errorMessage":"--max-tokens-budget must be a non-negative integer (0 means unlimited)","messagePattern":"--max-tokens-budget must be a non-negative integer \\(0 means unlimited\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/opencodereview/shared_flags.go","lineNumber":154,"sourceCode":"\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}\n\t}\n\treturn nil\n}\n\nfunc validateScanOptions(opts *scanOptions) error {\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","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/alibaba/open-code-review/blob/5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f/cmd/opencodereview/shared_flags.go#L136-L172","documentation":"This validation error is thrown by validateReviewOptions in cmd/opencodereview/shared_flags.go when the --max-tokens-budget flag is given a negative integer. The library requires that this flag be a non-negative integer; 0 has special meaning (unlimited budget), while any positive value caps the total token spend of the review run. Negative values indicate a configuration mistake, so the CLI rejects the run before doing any work.","triggerScenarios":"Running `ocr review --max-tokens-budget -1` (or any negative value). The flag is parsed into opts.maxTokensBudget by registerReviewFlags, then validateReviewOptions rejects negatives at line 153 before the pipeline starts.","commonSituations":"Scripts that compute a budget programmatically and produce a negative result (e.g. subtracting consumed tokens from a quota that is already exhausted); shell variables that are empty and expand to a bare '-' sign; typo'd hand-typed flags.","solutions":["Pass 0 instead of a negative number if you want an unlimited budget","Set a positive integer token budget, e.g. --max-tokens-budget 100000","Fix the script or environment variable that computed the negative value"],"exampleFix":"// before\nocr review --max-tokens-budget -500\n// after\nocr review --max-tokens-budget 0   # unlimited, or a positive integer like 100000","handlingStrategy":"validation","validationCode":"if [ \"$MAX_TOKENS_BUDGET\" -lt 0 ]; then MAX_TOKENS_BUDGET=0; fi\nocr review --max-tokens-budget \"$MAX_TOKENS_BUDGET\"","typeGuard":"func validBudget(n int) bool { return n >= 0 }","tryCatchPattern":null,"preventionTips":["Clamp computed budgets with a lower bound of 0 before passing the flag","Remember the convention: 0 = unlimited, never use negative numbers","Add a shell wrapper that validates numeric flags before invoking the CLI"],"tags":["cli","flag-validation","input-validation"],"backgroundTag":"invalid-cli-flag-value","analyzedSha":"5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f","analyzedAt":"2026-09-02T02:08:09.116Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}