{"record":{"id":"1cf5f6dc6928b285","repo":"yorukot/superfile","slug":"invalid-row-range-v-v-line-count-v","errorCode":null,"errorMessage":"invalid row range [%v, %v], line count : %v","messagePattern":"invalid row range \\[(.+?), (.+?)\\], line count : (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/internal/validation.go","lineNumber":401,"sourceCode":"func (m *model) validateComponentPlacement(lines []string, pos compPosition, border bool) error {\n\textractedLines, err := m.extractComponent(lines, pos)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failure while extracting content : %w\", err)\n\t}\n\n\tcntRow := pos.endRow - pos.stRow + 1\n\tcntCol := pos.endCol - pos.stCol + 1\n\textractedOut := strings.Join(extractedLines, \"\\n\")\n\tif err := validateRender(extractedOut, cntRow, cntCol, border); err != nil {\n\t\treturn fmt.Errorf(\"failure in extracted content : %w\", err)\n\t}\n\treturn nil\n}\n\n// Inclusive\nfunc (m *model) extractComponent(lines []string, pos compPosition) ([]string, error) {\n\tif 0 > pos.stRow || pos.stRow > pos.endRow || pos.endRow >= len(lines) {\n\t\treturn nil, fmt.Errorf(\"invalid row range [%v, %v], line count : %v\",\n\t\t\tpos.stRow, pos.endRow, len(lines))\n\t}\n\tfirstLineWidth := ansi.StringWidth(lines[0])\n\tif 0 > pos.stCol || pos.stCol > pos.endCol || pos.endCol >= firstLineWidth {\n\t\treturn nil, fmt.Errorf(\"invalid col range [%v, %v], first line width : %v\",\n\t\t\tpos.stCol, pos.endCol, firstLineWidth)\n\t}\n\n\tcntRow := pos.endRow - pos.stRow + 1\n\textractedLines := make([]string, cntRow)\n\tfor i := range cntRow {\n\t\torgIdx := pos.stRow + i\n\t\textractedLines[i] = ansi.Cut(lines[orgIdx], pos.stCol, pos.endCol+1)\n\t}\n\treturn extractedLines, nil\n}\n\ntype compPosition struct {","sourceCodeStart":383,"sourceCodeEnd":419,"githubUrl":"https://github.com/yorukot/superfile/blob/b72f550bc6e75913f48eb49fdd258e1a2df2fe88/src/internal/validation.go#L383-L419","documentation":"extractComponent slices a rectangular region out of rendered lines and first validates the row bounds. This error is thrown when pos.stRow is negative, stRow > endRow, or endRow is beyond the last line (len(lines)). The message includes the requested range and the actual line count for debugging.","triggerScenarios":"Calling validateComponentPlacement (which calls extractComponent) with a compPosition whose rows exceed the rendered content — e.g., endRow >= len(lines) after a component shrank, or a negative stRow from a bad layout computation.","commonSituations":"Terminal too small so the rendered content has fewer lines than the component's allocated rows; stale position data after re-render; arithmetic error in layout math producing negative start row.","solutions":["Clamp endRow to len(lines)-1 and stRow to >= 0 before calling validateComponentPlacement","Check terminal size handling: ensure the layout doesn't allocate more rows than available","Log len(lines) vs requested rows to find the off-by-one","Recompute compPosition from the freshly rendered content instead of cached values"],"exampleFix":"// before\nm.validateComponentPlacement(lines, pos, border)\n// after\nif pos.endRow >= len(lines) {\n\tpos.endRow = len(lines) - 1\n}\nif pos.stRow < 0 {\n\tpos.stRow = 0\n}\nif pos.stRow <= pos.endRow {\n\tm.validateComponentPlacement(lines, pos, border)\n}","handlingStrategy":"validation","validationCode":"func rowsInRange(lines []string, pos compPosition) bool {\n\treturn pos.stRow >= 0 && pos.stRow <= pos.endRow && pos.endRow < len(lines)\n}","typeGuard":null,"tryCatchPattern":"if err := m.validateComponentPlacement(lines, pos, border); err != nil {\n\tvar rngErr = err // message contains range and line count\n\tlog.Printf(\"row bounds violated: %v\", rngErr)\n\treturn fmt.Errorf(\"skipping validation for %v: %w\", pos, err)\n}","preventionTips":["Always clamp endRow to len(lines)-1 before extraction","Handle empty render output (len(lines)==0) explicitly","Verify terminal size is known before layout math","Prefer computing rows from the rendered slice length, not the desired height"],"tags":["go","validation","bounds","layout"],"backgroundTag":"index-out-of-range","analyzedSha":"b72f550bc6e75913f48eb49fdd258e1a2df2fe88","analyzedAt":"2026-09-01T04:38:08.254Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}