alibaba/open-code-review · error
OCR_LLM_TIMEOUT: %w
Error message
OCR_LLM_TIMEOUT: %w
What it means
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.
Source
Thrown at internal/llm/resolver.go:214
return ep
}
// parseTimeoutEnv reads and validates the OCR_LLM_TIMEOUT environment variable.
// Returns the parsed duration and true if set, or 0 and false if unset/empty.
// Returns an error for invalid values (non-integer, negative, overflow) to give
// the user clear feedback instead of silently falling back to the default.
func parseTimeoutEnv() (time.Duration, bool, error) {
raw := strings.TrimSpace(os.Getenv(envOCRLLMTimeout))
if raw == "" {
return 0, false, nil
}
sec, err := strconv.Atoi(raw)
if err != nil {
return 0, false, fmt.Errorf("OCR_LLM_TIMEOUT must be an integer (seconds): %w", err)
}
d, err := validateTimeoutSec(sec)
if err != nil {
return 0, false, fmt.Errorf("OCR_LLM_TIMEOUT: %w", err)
}
return d, true, nil
}
// validateTimeoutSec converts a config-file timeout (in seconds) to time.Duration.
// Returns 0 for zero input (use default). Rejects negative values and overflow.
func validateTimeoutSec(sec int) (time.Duration, error) {
if sec == 0 {
return 0, nil
}
if sec < 0 {
return 0, fmt.Errorf("timeout_sec must be non-negative, got %d", sec)
}
// Guard against overflow: time.Duration is int64 nanoseconds.
maxSec := int64(math.MaxInt64 / int64(time.Second))
if int64(sec) > maxSec {
return 0, fmt.Errorf("timeout_sec %d overflows time.Duration (max %d)", sec, maxSec)
}View on GitHub (pinned to 5cf97d0d15)
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)
Example fix
// before export OCR_LLM_TIMEOUT=-1 // after unset OCR_LLM_TIMEOUT # or: export OCR_LLM_TIMEOUT=0
Defensive patterns
Strategy: validation
Validate before calling
if v, err := strconv.Atoi(os.Getenv("OCR_LLM_TIMEOUT")); err == nil && v < 0 {
return errors.New("OCR_LLM_TIMEOUT cannot be negative; use 0 for default")
} Try / catch
if err != nil && strings.HasPrefix(err.Error(), "OCR_LLM_TIMEOUT:") {
return fmt.Errorf("range-check OCR_LLM_TIMEOUT: %w", err)
} Prevention
- 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)
When it happens
Trigger: 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).
Common situations: Using -1 intending "no timeout"; a sign typo; a script computing a bogus huge timeout.
Understand the failure class
- Timeouts: ETIMEDOUT, deadlines, and hung requests — what actually expires when a request times out.
Related errors
- OCR_LLM_TIMEOUT must be an integer (seconds): %w
- timeout_sec must be non-negative, got %d
- timeout_sec %d overflows time.Duration (max %d)
- background file %q is a directory, not a file
- background file %q is %d bytes, exceeding the maximum of %d
AI-assisted analysis of alibaba/open-code-review@5cf97d0d15 (2026-09-02).
Data as JSON: /api/errors/c8386ac065c5bde2.
Report an issue: GitHub.