rivo/tview · error

Invalid minimum row/column size

Error message

Invalid minimum row/column size

What it means

tview's Grid.SetMinSize panics immediately when either the row or column argument is negative. The library treats a negative minimum size as a programmer error rather than a recoverable condition, so it fails fast with this panic instead of clamping. Minimum sizes only make sense as non-negative absolute cell dimensions.

Solutions

  1. Ensure both arguments are >= 0 before calling SetMinSize; clamp with max(0, value) if the value is computed.
  2. If 'no minimum' is desired, pass 0 for that axis — do not pass a negative sentinel.
  3. Check where the negative number originates (user config, subtraction, off-by-one) and fix the source computation.
  4. If the value comes from user input, validate it before constructing the layout and report a friendly message instead of crashing.

Example fix

// before
grid.SetMinSize(minHeight, minWidth) // minHeight may be -1 after padding subtraction
// after
if minHeight < 0 { minHeight = 0 }
if minWidth < 0 { minWidth = 0 }
grid.SetMinSize(minHeight, minWidth)
Defensive patterns

Strategy: validation

Validate before calling

func safeSetMinSize(g *tview.Grid, row, col int) *tview.Grid {
    if row < 0 { row = 0 }
    if col < 0 { col = 0 }
    return g.SetMinSize(row, col)
}

Type guard

func validMinSize(row, col int) bool { return row >= 0 && col >= 0 }

Try / catch

func() {
    defer func() {
        if r := recover(); r != nil && r == "Invalid minimum row/column size" {
            log.Printf("SetMinSize rejected: %v", r)
        }
    }()
    grid.SetMinSize(row, col)
}()

Prevention

When it happens

Trigger: Calling grid.SetMinSize(row, column) with a negative value for either argument, e.g. SetMinSize(-1, 0) or passing a computed value that underflowed to negative (such as height - padding when padding > height).

Common situations: Computing the minimum from user input, layout math, or config values without clamping; subtracting margins/padding from a dimension that can be smaller than the subtraction; copying a call from another widget where -1 means 'auto' (Grid has no such convention).

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of rivo/tview@c15b79fa47 (2026-09-07). Data as JSON: /api/errors/05e02eb469485827. Report an issue: GitHub.

Appendix: source

Thrown at grid.go:143

// all row and column values are set to the given size values. See
// [Grid.SetColumns] for details on sizes.
func (g *Grid) SetSize(numRows, numColumns, rowSize, columnSize int) *Grid {
	g.rows = make([]int, numRows)
	for index := range g.rows {
		g.rows[index] = rowSize
	}
	g.columns = make([]int, numColumns)
	for index := range g.columns {
		g.columns[index] = columnSize
	}
	return g
}

// SetMinSize sets an absolute minimum width for rows and an absolute minimum
// height for columns. Panics if negative values are provided.
func (g *Grid) SetMinSize(row, column int) *Grid {
	if row < 0 || column < 0 {
		panic("Invalid minimum row/column size")
	}
	g.minHeight, g.minWidth = row, column
	return g
}

// SetGap sets the size of the gaps between neighboring primitives on the grid.
// If borders are drawn (see SetBorders()), these values are ignored and a gap
// of 1 is assumed. Panics if negative values are provided.
func (g *Grid) SetGap(row, column int) *Grid {
	if row < 0 || column < 0 {
		panic("Invalid gap size")
	}
	g.gapRows, g.gapColumns = row, column
	return g
}

// SetBorders sets whether or not borders are drawn around grid items. Setting
// this value to true will cause the gap values (see SetGap()) to be ignored and

View on GitHub (pinned to c15b79fa47)