{"record":{"id":"c8386ac065c5bde2","repo":"alibaba/open-code-review","slug":"ocr-llm-timeout-w","errorCode":null,"errorMessage":"OCR_LLM_TIMEOUT: %w","messagePattern":"OCR_LLM_TIMEOUT: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/llm/resolver.go","lineNumber":214,"sourceCode":"\treturn ep\n}\n\n// parseTimeoutEnv reads and validates the OCR_LLM_TIMEOUT environment variable.\n// Returns the parsed duration and true if set, or 0 and false if unset/empty.\n// Returns an error for invalid values (non-integer, negative, overflow) to give\n// the user clear feedback instead of silently falling back to the default.\nfunc parseTimeoutEnv() (time.Duration, bool, error) {\n\traw := strings.TrimSpace(os.Getenv(envOCRLLMTimeout))\n\tif raw == \"\" {\n\t\treturn 0, false, nil\n\t}\n\tsec, err := strconv.Atoi(raw)\n\tif err != nil {\n\t\treturn 0, false, fmt.Errorf(\"OCR_LLM_TIMEOUT must be an integer (seconds): %w\", err)\n\t}\n\td, err := validateTimeoutSec(sec)\n\tif err != nil {\n\t\treturn 0, false, fmt.Errorf(\"OCR_LLM_TIMEOUT: %w\", err)\n\t}\n\treturn d, true, nil\n}\n\n// validateTimeoutSec converts a config-file timeout (in seconds) to time.Duration.\n// Returns 0 for zero input (use default). Rejects negative values and overflow.\nfunc validateTimeoutSec(sec int) (time.Duration, error) {\n\tif sec == 0 {\n\t\treturn 0, nil\n\t}\n\tif sec < 0 {\n\t\treturn 0, fmt.Errorf(\"timeout_sec must be non-negative, got %d\", sec)\n\t}\n\t// Guard against overflow: time.Duration is int64 nanoseconds.\n\tmaxSec := int64(math.MaxInt64 / int64(time.Second))\n\tif int64(sec) > maxSec {\n\t\treturn 0, fmt.Errorf(\"timeout_sec %d overflows time.Duration (max %d)\", sec, maxSec)\n\t}","sourceCodeStart":196,"sourceCodeEnd":232,"githubUrl":"https://github.com/alibaba/open-code-review/blob/5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f/internal/llm/resolver.go#L196-L232","documentation":"After OCR_LLM_TIMEOUT parses as an integer, the value is passed to validateTimeoutSec, which rejects negatives and values that would overflow time.Duration. Failures are wrapped as \"OCR_LLM_TIMEOUT: %w\" so the underlying range problem (from [278]/[279]) is preserved.","triggerScenarios":"OCR_LLM_TIMEOUT set to a negative integer (e.g. -1) or an integer larger than math.MaxInt64 nanoseconds worth of seconds (~292 years, so in practice negatives or absurd values like 99999999999999).","commonSituations":"Using -1 intending \"no timeout\"; a sign typo; a script computing a bogus huge timeout.","solutions":["Set OCR_LLM_TIMEOUT to a positive integer within the allowed range","Use 0 (or unset) to fall back to the default timeout rather than a negative value","Check the wrapped message for the exact constraint (non-negative vs overflow max)"],"exampleFix":"// before\nexport OCR_LLM_TIMEOUT=-1\n// after\nunset OCR_LLM_TIMEOUT   # or: export OCR_LLM_TIMEOUT=0","handlingStrategy":"validation","validationCode":"if v, err := strconv.Atoi(os.Getenv(\"OCR_LLM_TIMEOUT\")); err == nil && v < 0 {\n    return errors.New(\"OCR_LLM_TIMEOUT cannot be negative; use 0 for default\")\n}","typeGuard":null,"tryCatchPattern":"if err != nil && strings.HasPrefix(err.Error(), \"OCR_LLM_TIMEOUT:\") {\n    return fmt.Errorf(\"range-check OCR_LLM_TIMEOUT: %w\", err)\n}","preventionTips":["Never use negative values to mean \"no timeout\" — use 0 or unset","Sanity-check scripted timeout values before export","Keep values in a practical range (seconds to hours)"],"tags":["env-vars","validation","timeout"],"backgroundTag":"invalid-env-var-format","analyzedSha":"5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f","analyzedAt":"2026-09-02T02:08:09.116Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}