chenhg5/cc-connect · error

value must be >= 0

Error message

value must be >= 0

What it means

The thinking-max-length setting must be non-negative: after a successful Atoi parse, a negative number is rejected because a negative truncation length is meaningless. This is an explicit range validation after the parse step.

Source

Thrown at core/engine.go:15155

					return e.displaySaveFunc(nil, &b, nil, nil, nil)
				}
				return nil
			},
		},
		{
			key:    "thinking_max_len",
			desc:   "Max chars for thinking messages (0=no truncation)",
			descZh: "思考消息最大长度 (0=不截断)",
			getFunc: func() string {
				return fmt.Sprintf("%d", e.display.ThinkingMaxLen)
			},
			setFunc: func(v string) error {
				n, err := strconv.Atoi(v)
				if err != nil {
					return fmt.Errorf("invalid integer: %s", v)
				}
				if n < 0 {
					return fmt.Errorf("value must be >= 0")
				}
				e.display.ThinkingMaxLen = n
				if e.displaySaveFunc != nil {
					return e.displaySaveFunc(nil, nil, &n, nil, nil)
				}
				return nil
			},
		},
		{
			key:    "tool_messages",
			desc:   "Whether tool progress messages are shown (true/false)",
			descZh: "是否显示工具进度消息 (true/false)",
			getFunc: func() string {
				return fmt.Sprintf("%t", e.display.ToolMessages)
			},
			setFunc: func(v string) error {
				b, err := strconv.ParseBool(v)
				if err != nil {

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Use 0 or a positive integer (0 typically means unlimited/no truncation — check the display logic).
  2. Clamp derived values: if n < 0 { n = 0 } before calling the setter.
  3. If 'unlimited' is desired, use the largest sensible positive value or the documented sentinel.

Example fix

// before
setFunc("-1") // error
// after
if n < 0 { n = 0 }
setFunc(strconv.Itoa(n))
Defensive patterns

Strategy: validation

Validate before calling

n, _ := strconv.Atoi(v); if n < 0 { n = 0 } // clamp before applying

Try / catch

if err := setThinkingMaxLen(v); err != nil {
    if strings.Contains(err.Error(), "value must be >= 0") { /* clamp and retry with 0 */ }
    return err
}

Prevention

When it happens

Trigger: Setting thinking-max-length to any negative integer, e.g. -1 or -500.

Common situations: User intends 'unlimited' and tries -1; a computed/default value accidentally goes negative when derived from other config.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06). Data as JSON: /api/errors/be431db8b0e6b9e9. Report an issue: GitHub.