{"record":{"id":"d7d6e16a2735631b","repo":"alibaba/open-code-review","slug":"invalid-max-tokens-q-must-be-a-positive-integer","errorCode":null,"errorMessage":"invalid max_tokens %q: must be a positive integer","messagePattern":"invalid max_tokens %q: must be a positive integer","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/opencodereview/config_cmd.go","lineNumber":501,"sourceCode":"\t\t\t\t}\n\t\t\t\tentry := cfg.Providers[cfg.Provider]\n\t\t\t\tentry.Model = value\n\t\t\t\tcfg.Providers[cfg.Provider] = entry\n\t\t\t} else {\n\t\t\t\tif cfg.CustomProviders == nil {\n\t\t\t\t\tcfg.CustomProviders = make(map[string]ProviderEntry)\n\t\t\t\t}\n\t\t\t\tentry := cfg.CustomProviders[cfg.Provider]\n\t\t\t\tentry.Model = value\n\t\t\t\tcfg.CustomProviders[cfg.Provider] = entry\n\t\t\t}\n\t\t} else {\n\t\t\tcfg.Model = value\n\t\t}\n\tcase \"max_tokens\":\n\t\tmaxTokens, err := strconv.Atoi(value)\n\t\tif err != nil || maxTokens <= 0 {\n\t\t\treturn fmt.Errorf(\"invalid max_tokens %q: must be a positive integer\", value)\n\t\t}\n\t\tcfg.MaxTokens = maxTokens\n\tcase \"effort\":\n\t\te, err := template.ParseEffort(value)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tcfg.Effort = string(e)\n\tcase \"llm.url\", \"llm.URL\":\n\t\tcfg.Llm.URL = value\n\tcase \"llm.auth_token\", \"llm.AuthToken\":\n\t\tcfg.Llm.AuthToken = value\n\tcase \"llm.auth_token_cmd\", \"llm.AuthTokenCmd\":\n\t\tcfg.Llm.AuthTokenCmd = value\n\tcase \"llm.auth_header\", \"llm.AuthHeader\":\n\t\tnormalized, err := llm.NormalizeAuthHeader(value)\n\t\tif err != nil {\n\t\t\treturn err","sourceCodeStart":483,"sourceCodeEnd":519,"githubUrl":"https://github.com/alibaba/open-code-review/blob/5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f/cmd/opencodereview/config_cmd.go#L483-L519","documentation":"Fires when the value passed to `ocr config set max_tokens` cannot be parsed as a decimal integer or parses to zero or a negative number. setConfigValue's max_tokens case uses strconv.Atoi on the raw CLI argument; since max_tokens controls the LLM completion budget, a non-positive value would make the API call invalid downstream, so the setter rejects it at input time rather than letting a bad config reach the provider.","triggerScenarios":"`ocr config set max_tokens <value>` where value is non-numeric (\"4096k\", \"\"), a float (\"4096.5\"), or a non-positive integer (0, -1).","commonSituations":"Typo like `max_tokens=4 096`; trying to disable the limit with 0 or -1 assuming it means unlimited; shell quoting stripping digits; pasting a value with a unit suffix (\"4k\").","solutions":["Run `ocr config set max_tokens 4096` with a plain positive integer","To remove a custom limit, unset/delete the key from the config file rather than setting 0","Check the shell quoting: quote the value if it contains spaces","Inspect the current value with `ocr config get max_tokens`"],"exampleFix":"// before\nocr config set max_tokens 4k\n// after\nocr config set max_tokens 4096","handlingStrategy":"validation","validationCode":"n, err := strconv.Atoi(value)\nif err != nil || n <= 0 {\n    return fmt.Errorf(\"max_tokens must be a positive integer, got %q\", value)\n}\n_ = runConfigSet(\"max_tokens\", value)","typeGuard":null,"tryCatchPattern":"if err := runConfigSet(\"max_tokens\", v); err != nil {\n    if strings.Contains(err.Error(), \"invalid max_tokens\") {\n        fmt.Fprintf(os.Stderr, \"%q is not a positive integer; e.g. 4096\\n\", v)\n    }\n}","preventionTips":["Always pass plain integers, never \"4k\" or \"4096.0\"","Remember 0 and negatives are rejected — there is no \"unlimited\" via max_tokens","Quote values in shell to avoid splitting","Re-check the value after setting with `ocr config get`"],"tags":["config","cli","validation"],"backgroundTag":"invalid-argument-format","analyzedSha":"5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f","analyzedAt":"2026-09-02T02:08:09.116Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}