{"record":{"id":"ef816d1bb0cce3c4","repo":"rivo/tview","slug":"invalid-gap-size","errorCode":null,"errorMessage":"Invalid gap size","messagePattern":"Invalid gap size","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"grid.go","lineNumber":154,"sourceCode":"\treturn g\n}\n\n// SetMinSize sets an absolute minimum width for rows and an absolute minimum\n// height for columns. Panics if negative values are provided.\nfunc (g *Grid) SetMinSize(row, column int) *Grid {\n\tif row < 0 || column < 0 {\n\t\tpanic(\"Invalid minimum row/column size\")\n\t}\n\tg.minHeight, g.minWidth = row, column\n\treturn g\n}\n\n// SetGap sets the size of the gaps between neighboring primitives on the grid.\n// If borders are drawn (see SetBorders()), these values are ignored and a gap\n// of 1 is assumed. Panics if negative values are provided.\nfunc (g *Grid) SetGap(row, column int) *Grid {\n\tif row < 0 || column < 0 {\n\t\tpanic(\"Invalid gap size\")\n\t}\n\tg.gapRows, g.gapColumns = row, column\n\treturn g\n}\n\n// SetBorders sets whether or not borders are drawn around grid items. Setting\n// this value to true will cause the gap values (see SetGap()) to be ignored and\n// automatically assumed to be 1 where the border graphics are drawn.\nfunc (g *Grid) SetBorders(borders bool) *Grid {\n\tg.borders = borders\n\treturn g\n}\n\n// SetBordersColor sets the color of the item borders.\nfunc (g *Grid) SetBordersColor(color tcell.Color) *Grid {\n\tg.bordersColor = color\n\treturn g\n}","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/rivo/tview/blob/c15b79fa47f27032f26647a75cb5a81720255076/grid.go#L136-L172","documentation":"tview's Grid.SetGap panics when either the row-gap or column-gap argument is negative. Gap sizes define the space between neighboring primitives and cannot meaningfully be negative, so the library panics rather than accepting the value. Note that gaps are ignored when borders are drawn (a gap of 1 is assumed).","triggerScenarios":"Calling grid.SetGap(row, column) with any negative argument, e.g. SetGap(-1, 2), or passing a computed negative value (e.g. spacing scaled by a negative factor or derived from unparsed input).","commonSituations":"Reading gap values from config/UI settings where -1 was used as 'default' or 'unset' in another system; arithmetic producing negatives (desired size minus content size); typos like SetGap(-1, -1) copied from codebases where -1 means 'inherit'.","solutions":["Pass 0 for 'no gap' and non-negative integers otherwise; clamp computed values with max(0, v).","If a negative value means 'use default', translate it explicitly: v < 0 → pass the library default instead.","Trace the source of the negative number (config parsing, scaling math) and fix it there.","If a config value feeds this, validate/normalize config at load time before building the UI."],"exampleFix":"// before\ngap := cfg.Gap // may be -1 meaning 'unset'\ngrid.SetGap(gap, gap)\n// after\nif gap < 0 { gap = 0 }\ngrid.SetGap(gap, gap)","handlingStrategy":"validation","validationCode":"func safeSetGap(g *tview.Grid, row, col int) *tview.Grid {\n    if row < 0 { row = 0 }\n    if col < 0 { col = 0 }\n    return g.SetGap(row, col)\n}","typeGuard":"func validGap(row, col int) bool { return row >= 0 && col >= 0 }","tryCatchPattern":"func() {\n    defer func() {\n        if r := recover(); r != nil && r == \"Invalid gap size\" {\n            log.Printf(\"SetGap rejected: %v\", r)\n        }\n    }()\n    grid.SetGap(row, col)\n}()","preventionTips":["Treat 0 as the only 'no gap' value; map any 'unset' sentinel to 0 first.","Normalize config-driven gap values during config validation.","Beware scaling math (negative multipliers, size-minus-content) that can go negative.","Remember gaps are ignored when borders are on — avoid compensating with negative values."],"tags":["panic","tview","layout","argument-validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"c15b79fa47f27032f26647a75cb5a81720255076","analyzedAt":"2026-09-07T09:42:56.840Z","contentChangedAt":"2026-09-07T09:42:56.840Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}