{"record":{"id":"8edaf860d06ec4bf","repo":"chenhg5/cc-connect","slug":"index-d-out-of-bounds","errorCode":null,"errorMessage":"index %d out of bounds","messagePattern":"index (.+?) out of bounds","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/engine.go","lineNumber":15688,"sourceCode":"\t\t\tif start < 1 || end < 1 || start > end || end > max {\n\t\t\t\treturn nil, fmt.Errorf(\"range %q out of bounds\", part)\n\t\t\t}\n\t\t\tfor idx := start; idx <= end; idx++ {\n\t\t\t\tif _, ok := seen[idx]; ok {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tseen[idx] = struct{}{}\n\t\t\t\tindices = append(indices, idx)\n\t\t\t}\n\t\t\tcontinue\n\t\t}\n\n\t\tidx, err := strconv.Atoi(part)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tif idx < 1 || idx > max {\n\t\t\treturn nil, fmt.Errorf(\"index %d out of bounds\", idx)\n\t\t}\n\t\tif _, ok := seen[idx]; ok {\n\t\t\tcontinue\n\t\t}\n\t\tseen[idx] = struct{}{}\n\t\tindices = append(indices, idx)\n\t}\n\n\treturn indices, nil\n}\n\nfunc (e *Engine) cmdDeleteBatch(p Platform, msg *Message, deleter SessionDeleter, sessions []AgentSessionInfo, indices []int) {\n\tlines := make([]string, 0, len(indices))\n\tfor _, idx := range indices {\n\t\tmatched := &sessions[idx-1]\n\t\tif line := e.deleteSingleSessionReply(msg, deleter, matched); line != \"\" {\n\t\t\tlines = append(lines, line)\n\t\t}","sourceCodeStart":15670,"sourceCodeEnd":15706,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/core/engine.go#L15670-L15706","documentation":"parseDeleteBatchIndices rejects any single index that is not within the valid 1..max range. Each comma-separated item must parse as an integer and reference an existing item; zero, negative, or too-large indices produce this error.","triggerScenarios":"Passing an index like '0', '-1', or '25' when only 20 items exist (max=20) to parseDeleteBatchIndices, e.g. via a '/history delete 25' command.","commonSituations":"1-based vs 0-based indexing confusion; the listed items changed since the user looked; off-by-one errors in generated specs.","solutions":["Use indices between 1 and the number of displayed items","Re-list the history/session items to confirm valid indices before deleting","Fix callers that build 0-based indices to add 1 before invoking the parser"],"exampleFix":"// before\nparseDeleteBatchIndices(\"0,25\", 20)\n// after\nparseDeleteBatchIndices(\"1,20\", 20)","handlingStrategy":"validation","validationCode":"idx, err := strconv.Atoi(part)\nif err != nil || idx < 1 || idx > max {\n    return fmt.Errorf(\"index must be between 1 and %d, got %q\", max, part)\n}","typeGuard":null,"tryCatchPattern":"if _, err := parseDeleteBatchIndices(spec, max); err != nil {\n    reply(\"bad index: %v (valid: 1-%d)\", err, max)\n}","preventionTips":["Remember indices are 1-based; convert 0-based values with +1 before parsing","Re-list items right before deleting to keep indices valid","Clamp or reject generated indices against the current item count"],"tags":["parsing","out-of-bounds","batch-delete"],"backgroundTag":"index-out-of-range","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"}