chenhg5/cc-connect · error

range %q out of bounds

Error message

range %q out of bounds

What it means

Batch-item range parser rejected a range like "5-3" or "12-40" where max is lower: start/end are not both >=1, start > end, or end exceeds the number of available items. The message echoes the offending range expression.

Source

Thrown at core/engine.go:15671

		if part == "" {
			return nil, fmt.Errorf("empty batch item")
		}

		if strings.Contains(part, "-") {
			bounds := strings.Split(part, "-")
			if len(bounds) != 2 || bounds[0] == "" || bounds[1] == "" {
				return nil, fmt.Errorf("invalid range %q", part)
			}
			start, err := strconv.Atoi(bounds[0])
			if err != nil {
				return nil, err
			}
			end, err := strconv.Atoi(bounds[1])
			if err != nil {
				return nil, err
			}
			if start < 1 || end < 1 || start > end || end > max {
				return nil, fmt.Errorf("range %q out of bounds", part)
			}
			for idx := start; idx <= end; idx++ {
				if _, ok := seen[idx]; ok {
					continue
				}
				seen[idx] = struct{}{}
				indices = append(indices, idx)
			}
			continue
		}

		idx, err := strconv.Atoi(part)
		if err != nil {
			return nil, err
		}
		if idx < 1 || idx > max {
			return nil, fmt.Errorf("index %d out of bounds", idx)
		}

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Re-check the number of items (e.g. via the history listing) and use ranges within 1..max
  2. Fix inverted ranges so start <= end, e.g. '3-7' not '7-3'
  3. Ensure bounds are >= 1; index numbering starts at 1
  4. Refresh the list before composing the delete spec so indices match current items

Example fix

// before
parseDeleteBatchIndices("1-50", 20) // max is 20
// after
parseDeleteBatchIndices("1-20", 20)
Defensive patterns

Strategy: validation

Validate before calling

if max <= 0 {
    return errors.New("nothing to delete")
}
if start < 1 || end > max || start > end {
    return fmt.Errorf("range must be within 1-%d", max)
}

Try / catch

if _, err := parseDeleteBatchIndices(spec, count); err != nil {
    reply("out of range: %v (valid: 1-%d)", err, count)
}

Prevention

When it happens

Trigger: Passing a range whose start or end exceeds the item count (e.g. '1-50' when max=20), a zero or negative bound ('0-5'), or an inverted range ('7-3').

Common situations: User guesses the number of history items and over-ranges; stale UI listing fewer items than the spec assumes after items were deleted.

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/bcc8db712bea9642. Report an issue: GitHub.