chenhg5/cc-connect · error
invalid range %q
Error message
invalid range %q
What it means
This error is returned when a batch spec item containing a dash is not a well-formed N-M range. The item is split on '-' and must yield exactly two non-empty bounds; anything else (e.g. '5-', '-3', '1-2-3') is rejected.
Source
Thrown at core/engine.go:15660
func parseDeleteBatchIndices(spec string, max int) ([]int, error) {
parts := strings.Split(spec, ",")
if len(parts) == 0 {
return nil, fmt.Errorf("empty batch spec")
}
seen := make(map[int]struct{}, len(parts))
indices := make([]int, 0, len(parts))
for _, part := range parts {
part = strings.TrimSpace(part)
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)View on GitHub (pinned to 4000b2338a)
Solutions
- Write the range as start-end with both bounds present, e.g. '3-7'
- Ensure ranges appear only once per item (no extra dashes)
- Validate the range format in the command handler before invoking the parser
Example fix
// before
parseDeleteBatchIndices("5-", 20)
// after
parseDeleteBatchIndices("5-10", 20) Defensive patterns
Strategy: validation
Validate before calling
for _, item := range strings.Split(spec, ",") {
if strings.Contains(item, "-") {
b := strings.Split(item, "-")
if len(b) != 2 || b[0] == "" || b[1] == "" {
return fmt.Errorf("range must be start-end, got %q", item)
}
}
} Try / catch
if _, err := parseDeleteBatchIndices(spec, max); err != nil {
reply("bad range in %q: %v (format: start-end)", spec, err)
} Prevention
- Show the expected range syntax (N-M) in command help text
- Validate each item with a regex like ^\d+(-\d+)?$ before calling the parser
- Avoid negative-number ambiguity by forbidding '-' not surrounded by digits
When it happens
Trigger: Passing a malformed range like '5-' (missing end), '-3' (missing start), or '1-2-3' (more than one dash) inside the comma-separated spec.
Common situations: Typo when typing a delete range; confusion between negative numbers and ranges; copy-paste errors from docs.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- config: %s.history_max_len must be >= 0
- empty batch spec
- empty batch item
- range %q out of bounds
- cannot parse local reference
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/a9eb981522755338.
Report an issue: GitHub.