chenhg5/cc-connect · error

empty batch spec

Error message

empty batch spec

What it means

parseDeleteBatchIndices rejects an empty batch specification string. It splits the spec on commas; although strings.Split never returns an empty slice for an empty input (it returns [""]), this guard documents and enforces that an empty spec is invalid before parsing indices.

Source

Thrown at core/engine.go:15646

func isExplicitDeleteBatchArg(arg string) bool {
	if strings.Contains(arg, ",") {
		return true
	}
	if !strings.Contains(arg, "-") {
		return false
	}
	for _, r := range arg {
		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

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Supply a comma-separated list of indices, e.g. '1,3,5-7'
  2. Check for an empty/whitespace-only spec in the command handler and prompt the user before calling the parser
  3. Use strings.TrimSpace on user input and reject it early with a friendly usage message

Example fix

// before
parseDeleteBatchIndices("", 20)
// after
spec := strings.TrimSpace(userInput)
if spec == "" { return fmt.Errorf("usage: delete <indices, e.g. 1,3,5-7>") }
parseDeleteBatchIndices(spec, 20)
Defensive patterns

Strategy: validation

Validate before calling

spec := strings.TrimSpace(input)
if spec == "" {
    return errors.New("no indices given; e.g. 1,3,5-7")
}

Try / catch

err := runDeleteBatch(spec, max)
if err != nil {
    slog.Warn("batch delete rejected", "err", err)
    reply("usage: delete <indices, e.g. 1,3,5-7>")
}

Prevention

When it happens

Trigger: Calling parseDeleteBatchIndices with an empty spec string, e.g. parseDeleteBatchIndices("", max), typically from a '/history delete' style command invoked with no indices argument.

Common situations: A user runs a batch-delete command without supplying the index list; a UI passes an empty text field value straight through to the parser.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


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