yorukot/superfile · error

invalid col range [%v, %v], first line width : %v

Error message

invalid col range [%v, %v], first line width : %v

What it means

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.

Source

Thrown at src/internal/validation.go:406

	cntRow := pos.endRow - pos.stRow + 1
	cntCol := pos.endCol - pos.stCol + 1
	extractedOut := strings.Join(extractedLines, "\n")
	if err := validateRender(extractedOut, cntRow, cntCol, border); err != nil {
		return fmt.Errorf("failure in extracted content : %w", err)
	}
	return nil
}

// Inclusive
func (m *model) extractComponent(lines []string, pos compPosition) ([]string, error) {
	if 0 > pos.stRow || pos.stRow > pos.endRow || pos.endRow >= len(lines) {
		return nil, fmt.Errorf("invalid row range [%v, %v], line count : %v",
			pos.stRow, pos.endRow, len(lines))
	}
	firstLineWidth := ansi.StringWidth(lines[0])
	if 0 > pos.stCol || pos.stCol > pos.endCol || pos.endCol >= firstLineWidth {
		return nil, fmt.Errorf("invalid col range [%v, %v], first line width : %v",
			pos.stCol, pos.endCol, firstLineWidth)
	}

	cntRow := pos.endRow - pos.stRow + 1
	extractedLines := make([]string, cntRow)
	for i := range cntRow {
		orgIdx := pos.stRow + i
		extractedLines[i] = ansi.Cut(lines[orgIdx], pos.stCol, pos.endCol+1)
	}
	return extractedLines, nil
}

type compPosition struct {
	stRow  int
	stCol  int
	endRow int
	endCol int
}

View on GitHub (pinned to b72f550bc6)

Solutions

  1. Measure widths with ansi.StringWidth on every line, not just the first, when computing positions
  2. Clamp endCol to ansi.StringWidth(lines[0])-1 and stCol to >= 0
  3. Verify component rendering accounts for borders/extra glyphs inflating width
  4. Handle empty first line (width 0) before extraction

Example fix

// before
pos.endCol = pos.stCol + desiredWidth
m.validateComponentPlacement(lines, pos, border)
// after
lineWidth := ansi.StringWidth(lines[0])
if pos.endCol >= lineWidth {
	pos.endCol = lineWidth - 1
}
m.validateComponentPlacement(lines, pos, border)
Defensive patterns

Strategy: validation

Validate before calling

func colsInRange(lines []string, pos compPosition) bool {
	if len(lines) == 0 { return false }
	w := ansi.StringWidth(lines[0])
	return pos.stCol >= 0 && pos.stCol <= pos.endCol && pos.endCol < w
}

Try / catch

if err := m.validateComponentPlacement(lines, pos, border); err != nil {
	log.Printf("col bounds violated (width=%d): %v", ansi.StringWidth(lines[0]), err)
	return err
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of yorukot/superfile@b72f550bc6 (2026-09-01). Data as JSON: /api/errors/a0336ada946852fb. Report an issue: GitHub.