{"record":{"id":"a7fe966dfef2e1f8","repo":"spectreconsole/spectre.console","slug":"table-row-index-cannot-exceed-the-number-of-rows-i","errorCode":null,"errorMessage":"Table row index cannot exceed the number of rows in the table.","messagePattern":"Table row 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":98,"sourceCode":"    /// <summary>\n    /// Update a table cell at the specified index.\n    /// </summary>\n    /// <param name=\"row\">Index of cell row.</param>\n    /// <param name=\"column\">index of cell column.</param>\n    /// <param name=\"cellData\">The new cells details.</param>\n    public void Update(int row, int column, IRenderable cellData)\n    {\n        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","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/spectreconsole/spectre.console/blob/0acc92fada6c42f13984e79c2b5f3d993bdfb099/src/Spectre.Console/Widgets/Table/TableRowCollection.cs#L80-L116","documentation":"In TableRowCollection.Update, after the negative check, if row >= _list.Count it throws IndexOutOfRangeException: 'Table row index cannot exceed the number of rows in the table.' The row must reference an existing row.","triggerScenarios":"Calling Update with a row index equal to or greater than the current number of rows (e.g. index == count, or referencing a row that was already removed).","commonSituations":"Stale index captured before rows were removed; assuming rows exist after dynamic modification; using table.Rows.Count (one-past-last) as a valid index; concurrent removal making the index invalid.","solutions":["Check row < table.Rows.Count before calling Update.","Capture a fresh count immediately before the call rather than caching it.","After RemoveAt/Insert, recompute any stored row indices."],"exampleFix":"// before\ntable.Rows.Update(rowIndex, colIndex, cell);\n\n// after\nif (rowIndex >= 0 && rowIndex < table.Rows.Count)\n    table.Rows.Update(rowIndex, colIndex, cell);","handlingStrategy":"validation","validationCode":"if (row < 0 || row >= table.Rows.Count) return; // or throw\ntable.Rows.Update(row, column, cell);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check row < table.Rows.Count immediately before the call; do not cache the count.","Treat table.Rows.Count as one-past-the-last valid index.","After removing rows, recompute any stored indices."],"tags":["table","row","index-bounds","argument"],"backgroundTag":null,"analyzedSha":"0acc92fada6c42f13984e79c2b5f3d993bdfb099","analyzedAt":"2026-08-13T18:27:21.983Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}