{"record":{"id":"a0336ada946852fb","repo":"yorukot/superfile","slug":"invalid-col-range-v-v-first-line-width-v","errorCode":null,"errorMessage":"invalid col range [%v, %v], first line width : %v","messagePattern":"invalid col range \\[(.+?), (.+?)\\], first line width : (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/internal/validation.go","lineNumber":406,"sourceCode":"\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 {\n\tstRow  int\n\tstCol  int\n\tendRow int\n\tendCol int\n}","sourceCodeStart":388,"sourceCodeEnd":424,"githubUrl":"https://github.com/yorukot/superfile/blob/b72f550bc6e75913f48eb49fdd258e1a2df2fe88/src/internal/validation.go#L388-L424","documentation":"After validating rows, extractComponent validates column bounds against the width of the first line (measured with ansi.StringWidth, ANSI-aware). This error is thrown when pos.stCol is negative, stCol > endCol, or endCol >= the first line's visual width. The message reports the requested range and the measured first-line width.","triggerScenarios":"The component region's columns exceed the rendered first line's width — e.g., the component rendered narrower than expected due to terminal width, ANSI escape sequences, or wide-character miscalculation.","commonSituations":"Components containing CJK/emoji characters where byte length vs display width mismatch; using len(line) instead of ansi.StringWidth when computing positions; lines[0] shorter than other lines because the first row is partially empty.","solutions":["Measure widths with ansi.StringWidth on every line, not just the first, when computing positions","Clamp endCol to ansi.StringWidth(lines[0])-1 and stCol to >= 0","Verify component rendering accounts for borders/extra glyphs inflating width","Handle empty first line (width 0) before extraction"],"exampleFix":"// before\npos.endCol = pos.stCol + desiredWidth\nm.validateComponentPlacement(lines, pos, border)\n// after\nlineWidth := ansi.StringWidth(lines[0])\nif pos.endCol >= lineWidth {\n\tpos.endCol = lineWidth - 1\n}\nm.validateComponentPlacement(lines, pos, border)","handlingStrategy":"validation","validationCode":"func colsInRange(lines []string, pos compPosition) bool {\n\tif len(lines) == 0 { return false }\n\tw := ansi.StringWidth(lines[0])\n\treturn pos.stCol >= 0 && pos.stCol <= pos.endCol && pos.endCol < w\n}","typeGuard":null,"tryCatchPattern":"if err := m.validateComponentPlacement(lines, pos, border); err != nil {\n\tlog.Printf(\"col bounds violated (width=%d): %v\", ansi.StringWidth(lines[0]), err)\n\treturn err\n}","preventionTips":["Use ansi.StringWidth on the actual first line, never assumed width","Clamp endCol to measured width - 1 before extraction","Handle a zero-width first line before computing columns","Test layouts on narrow terminals where the first line may be shorter"],"tags":["go","validation","ansi","bounds"],"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"}