{"record":{"id":"039fabd8b2de8dfc","repo":"chenhg5/cc-connect","slug":"empty-batch-spec","errorCode":null,"errorMessage":"empty batch spec","messagePattern":"empty batch spec","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/engine.go","lineNumber":15646,"sourceCode":"func isExplicitDeleteBatchArg(arg string) bool {\n\tif strings.Contains(arg, \",\") {\n\t\treturn true\n\t}\n\tif !strings.Contains(arg, \"-\") {\n\t\treturn false\n\t}\n\tfor _, r := range arg {\n\t\tif (r < '0' || r > '9') && r != '-' {\n\t\t\treturn false\n\t\t}\n\t}\n\treturn true\n}\n\nfunc parseDeleteBatchIndices(spec string, max int) ([]int, error) {\n\tparts := strings.Split(spec, \",\")\n\tif len(parts) == 0 {\n\t\treturn nil, fmt.Errorf(\"empty batch spec\")\n\t}\n\tseen := make(map[int]struct{}, len(parts))\n\tindices := make([]int, 0, len(parts))\n\n\tfor _, part := range parts {\n\t\tpart = strings.TrimSpace(part)\n\t\tif part == \"\" {\n\t\t\treturn nil, fmt.Errorf(\"empty batch item\")\n\t\t}\n\n\t\tif strings.Contains(part, \"-\") {\n\t\t\tbounds := strings.Split(part, \"-\")\n\t\t\tif len(bounds) != 2 || bounds[0] == \"\" || bounds[1] == \"\" {\n\t\t\t\treturn nil, fmt.Errorf(\"invalid range %q\", part)\n\t\t\t}\n\t\t\tstart, err := strconv.Atoi(bounds[0])\n\t\t\tif err != nil {\n\t\t\t\treturn nil, err","sourceCodeStart":15628,"sourceCodeEnd":15664,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/core/engine.go#L15628-L15664","documentation":"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.","triggerScenarios":"Calling parseDeleteBatchIndices with an empty spec string, e.g. parseDeleteBatchIndices(\"\", max), typically from a '/history delete' style command invoked with no indices argument.","commonSituations":"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.","solutions":["Supply a comma-separated list of indices, e.g. '1,3,5-7'","Check for an empty/whitespace-only spec in the command handler and prompt the user before calling the parser","Use strings.TrimSpace on user input and reject it early with a friendly usage message"],"exampleFix":"// before\nparseDeleteBatchIndices(\"\", 20)\n// after\nspec := strings.TrimSpace(userInput)\nif spec == \"\" { return fmt.Errorf(\"usage: delete <indices, e.g. 1,3,5-7>\") }\nparseDeleteBatchIndices(spec, 20)","handlingStrategy":"validation","validationCode":"spec := strings.TrimSpace(input)\nif spec == \"\" {\n    return errors.New(\"no indices given; e.g. 1,3,5-7\")\n}","typeGuard":null,"tryCatchPattern":"err := runDeleteBatch(spec, max)\nif err != nil {\n    slog.Warn(\"batch delete rejected\", \"err\", err)\n    reply(\"usage: delete <indices, e.g. 1,3,5-7>\")\n}","preventionTips":["Require an explicit argument for batch-delete commands and show usage when missing","Trim and check input in the command handler before parsing","Provide a default no-op message when the user supplies nothing"],"tags":["parsing","validation","batch-delete"],"backgroundTag":"empty-required-field","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}