{"record":{"id":"a5ea8185819e9c99","repo":"spectreconsole/spectre.console","slug":"table-column-index-cannot-be-negative","errorCode":null,"errorMessage":"Table column index cannot be negative.","messagePattern":"Table column index cannot be negative\\.","errorType":"validation","errorClass":"IndexOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Spectre.Console/Widgets/Table/TableRowCollection.cs","lineNumber":106,"sourceCode":"        ArgumentNullException.ThrowIfNull(cellData);\n\n        lock (_lock)\n        {\n            if (row < 0)\n            {\n                throw new IndexOutOfRangeException(\"Table row index cannot be negative.\");\n            }\n            else if (row >= _list.Count)\n            {\n                throw new IndexOutOfRangeException(\"Table row index cannot exceed the number of rows in the table.\");\n            }\n\n            var tableRow = _list.ElementAt(row);\n            var currentRenderables = tableRow.ToList();\n\n            if (column < 0)\n            {\n                throw new IndexOutOfRangeException(\"Table column index cannot be negative.\");\n            }\n            else if (column >= currentRenderables.Count)\n            {\n                throw new IndexOutOfRangeException(\"Table column index cannot exceed the number of rows in the table.\");\n            }\n\n            currentRenderables.RemoveAt(column);\n\n            currentRenderables.Insert(column, cellData);\n\n            var newTableRow = new TableRow(currentRenderables);\n\n            _list.RemoveAt(row);\n\n            _list.Insert(row, newTableRow);\n        }\n    }\n","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/spectreconsole/spectre.console/blob/0acc92fada6c42f13984e79c2b5f3d993bdfb099/src/Spectre.Console/Widgets/Table/TableRowCollection.cs#L88-L124","documentation":"After validating the row in TableRowCollection.Update, the method checks the column index. If column < 0 it throws IndexOutOfRangeException: 'Table column index cannot be negative.' Column is indexed within the target row's renderables.","triggerScenarios":"Calling Update with a negative column argument — typically a computed column position that underflowed to below zero.","commonSituations":"Off-by-one when mapping a logical column to an index; a decremented loop variable passing zero; passing an unchecked external index for the column.","solutions":["Validate column >= 0 before calling Update.","Bound-check against the target row's column count (table.Columns.Count) and clamp/skip.","Treat column indices as zero-based and never subtract past zero."],"exampleFix":"// before\ntable.Rows.Update(rowIndex, colIndex, cell);\n\n// after\nif (colIndex >= 0 && colIndex < table.Columns.Count)\n    table.Rows.Update(rowIndex, colIndex, cell);","handlingStrategy":"validation","validationCode":"if (column < 0) throw new ArgumentOutOfRangeException(nameof(column));\ntable.Rows.Update(row, column, cell);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Bound-check column against [0, table.Columns.Count) before Update.","Treat column indices as zero-based; never subtract past zero.","Validate external column indices at the boundary."],"tags":["table","column","index-bounds","argument"],"backgroundTag":null,"analyzedSha":"0acc92fada6c42f13984e79c2b5f3d993bdfb099","analyzedAt":"2026-08-13T18:27:21.983Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}