{"record":{"id":"56a144faa5364c1a","repo":"spectreconsole/spectre.console","slug":"table-row-index-cannot-be-negative","errorCode":null,"errorMessage":"Table row index cannot be negative.","messagePattern":"Table row index cannot be negative\\.","errorType":"validation","errorClass":"IndexOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Spectre.Console/Widgets/Table/TableRowCollection.cs","lineNumber":94,"sourceCode":"            return _list.IndexOf(row);\n        }\n    }\n\n    /// <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","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/spectreconsole/spectre.console/blob/0acc92fada6c42f13984e79c2b5f3d993bdfb099/src/Spectre.Console/Widgets/Table/TableRowCollection.cs#L76-L112","documentation":"TableRowCollection.Update(int row, int column, IRenderable cellData) validates the row index first. If row < 0 it throws IndexOutOfRangeException with 'Table row index cannot be negative.' The method is the in-place cell replacement API used by table.UpdateCell-style extensions.","triggerScenarios":"Calling Update with a negative row argument, e.g. a computed index that underflows, or passing a position from data/calculations that went below zero.","commonSituations":"Off-by-one when subtracting from a count; using an index variable decremented in a loop past zero; passing an unchecked external index; off-by-one after a RemoveAt shifts indices.","solutions":["Validate row >= 0 before calling Update.","Bound-check against table.Rows.Count and clamp/skip when out of range.","Recompute indices after structural changes (Insert/RemoveAt) that shift row positions."],"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) throw new ArgumentOutOfRangeException(nameof(row));\ntable.Rows.Update(row, column, cell);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always bound-check row against [0, table.Rows.Count) before Update.","Recompute indices after Insert/RemoveAt that shift positions.","Validate external indices at the boundary with a minimum of 0."],"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"}