{"record":{"id":"0a1ca1a739b8398e","repo":"spectreconsole/spectre.console","slug":"table-column-index-cannot-exceed-the-number-of-row","errorCode":null,"errorMessage":"Table column index cannot exceed the number of rows in the table.","messagePattern":"Table column index cannot exceed the number of rows in the table\\.","errorType":"validation","errorClass":"IndexOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Spectre.Console/Widgets/Table/TableRowCollection.cs","lineNumber":110,"sourceCode":"            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\n    /// <summary>\n    /// Removes a row at the specified index.\n    /// </summary>\n    /// <param name=\"index\">The index to remove a row at.</param>","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/spectreconsole/spectre.console/blob/0acc92fada6c42f13984e79c2b5f3d993bdfb099/src/Spectre.Console/Widgets/Table/TableRowCollection.cs#L92-L128","documentation":"In TableRowCollection.Update, if column >= the row's renderable count it throws IndexOutOfRangeException. NOTE: the thrown message says 'Table column index cannot exceed the number of ROWS in the table' — this is a copy-paste bug in the message text; it actually guards the column bound, not rows.","triggerScenarios":"Calling Update with a column index >= the number of columns in that row (e.g. column == table.Columns.Count, or referencing a column that does not exist).","commonSituations":"Using table.Columns.Count as a valid index (it is one-past-last); stale column index after AddColumn/RemoveColumn; assuming a row has more columns than defined; confusing zero-based vs count when mapping data to columns.","solutions":["Check column < table.Columns.Count (and column >= 0) before calling Update.","When debugging, ignore the misleading 'rows' word in the message — verify the column index.","Recompute column indices after structural column changes."],"exampleFix":"// before\ntable.Rows.Update(rowIndex, colIndex, cell); // colIndex == Columns.Count\n\n// after\nif (colIndex >= 0 && colIndex < table.Columns.Count)\n    table.Rows.Update(rowIndex, colIndex, cell);","handlingStrategy":"validation","validationCode":"if (column < 0 || column >= table.Columns.Count) return; // or throw\ntable.Rows.Update(row, column, cell);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check column < table.Columns.Count before calling Update.","When debugging, remember the message wrongly says 'rows' — verify the column index.","Use table.Columns.Count as an exclusive upper bound, not a valid index."],"tags":["table","column","index-bounds","argument","message-bug"],"backgroundTag":null,"analyzedSha":"0acc92fada6c42f13984e79c2b5f3d993bdfb099","analyzedAt":"2026-08-13T18:27:21.983Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}