chenhg5/cc-connect · error

empty batch item

Error message

empty batch item

What it means

parseDeleteBatchIndices returns this error when an individual comma-separated item in the batch spec is empty after trimming whitespace, e.g. a trailing comma or double comma. The parser requires every item to be a non-empty index or range.

Source

Thrown at core/engine.go:15654

		if (r < '0' || r > '9') && r != '-' {
			return false
		}
	}
	return true
}

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)
			}

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Remove stray/extra commas from the spec, e.g. use '1,3' not '1,,3,'
  2. Sanitize the input before parsing: split, drop empty parts or reject early
  3. Trim the whole spec and collapse repeated commas before calling the parser

Example fix

// before
parseDeleteBatchIndices("1,,3", 20)
// after
parseDeleteBatchIndices("1,3", 20)
Defensive patterns

Strategy: validation

Validate before calling

parts := strings.Split(spec, ",")
for _, p := range parts {
    if strings.TrimSpace(p) == "" {
        return errors.New("spec contains an empty item: " + spec)
    }
}

Try / catch

_, err := parseDeleteBatchIndices(spec, max)
if err != nil {
    reply("invalid list %q: %v", spec, err)
}

Prevention

When it happens

Trigger: Passing a spec with empty items such as '1,,3', '1,3,', or ',2' to parseDeleteBatchIndices.

Common situations: Users hand-typing index lists with stray commas; scripts concatenating lists where an element is blank.

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


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