{"record":{"id":"7012fdc536a64ed2","repo":"spectreconsole/spectre.console","slug":"the-number-of-row-columns-including-spans-are-gr","errorCode":null,"errorMessage":"The number of row columns (including spans) are greater than the number of table columns. Expected {_table.Columns.Count} but got {totalSpan}.","messagePattern":"The number of row columns \\(including spans\\) are greater than the number of table columns\\. Expected (.+?) but got (.+?)\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Spectre.Console/Widgets/Table/TableRowCollection.cs","lineNumber":195,"sourceCode":"\n        // Calculate total span considering TableCell instances\n        var totalSpan = 0;\n        for (var i = 0; i < row.Count; i++)\n        {\n            var cell = row[i];\n            if (cell is TableCell tableCell)\n            {\n                totalSpan += tableCell.ColumnSpan;\n            }\n            else\n            {\n                totalSpan++;\n            }\n        }\n\n        if (totalSpan > _table.Columns.Count)\n        {\n            throw new InvalidOperationException($\"The number of row columns (including spans) are greater than the number of table columns. Expected {_table.Columns.Count} but got {totalSpan}.\");\n        }\n\n        // Need to add missing columns\n        if (totalSpan < _table.Columns.Count)\n        {\n            var diff = _table.Columns.Count - totalSpan;\n            Enumerable.Range(0, diff).ForEach(_ => row.Add(Text.Empty));\n        }\n\n        return row;\n    }\n}","sourceCodeStart":177,"sourceCodeEnd":207,"githubUrl":"https://github.com/spectreconsole/spectre.console/blob/0acc92fada6c42f13984e79c2b5f3d993bdfb099/src/Spectre.Console/Widgets/Table/TableRowCollection.cs#L177-L207","documentation":"When adding a row (AddRow overloads), CreateRow sums each cell's contribution: a plain IRenderable counts as 1, a TableCell counts as its ColumnSpan. If the total exceeds the number of columns defined on the table, it throws InvalidOperationException. Note the asymmetric behavior: fewer cells than columns is allowed (the method pads with empty Text cells), but more is rejected. The message wording ('are greater than') is slightly ungrammatical.","triggerScenarios":"Defining N columns via AddColumn/AddColumns but adding a row whose cells/spans sum to > N — e.g. 3 columns but a row with 4 cells, or a TableCell.Span(3) plus two more plain cells (total 4) against 3 columns.","commonSituations":"Forgetting to AddColumn(s) before AddRow; mismatched counts after dynamically adding/removing columns; a spanning cell computed from data whose span pushes the total over; building rows from a 2D array whose width exceeds the declared columns.","solutions":["Ensure table columns count >= total row span before adding rows: add missing AddColumn calls first.","Reduce the cells in the row, or lower a TableCell span, so the sum <= table.Columns.Count.","If rows may have fewer cells, rely on the built-in padding (do nothing) — only excess throws.","Compute span as min(requestedSpan, table.Columns.Count - otherCells)."],"exampleFix":"// before\nvar table = new Table();\ntable.AddColumns(\"A\", \"B\", \"C\");\ntable.AddRow(new TableCell(\"wide\").Span(3), new Markup(\"extra\")); // total 4 > 3\n\n// after\nvar table = new Table();\ntable.AddColumns(\"A\", \"B\", \"C\", \"D\");\ntable.AddRow(new TableCell(\"wide\").Span(3), new Markup(\"extra\")); // total 4 == 4","handlingStrategy":"validation","validationCode":"int totalSpan = rowCells.Sum(c => c is TableCell tc ? tc.ColumnSpan : 1);\nif (totalSpan > table.Columns.Count)\n    table.AddColumns(Enumerable.Range(0, totalSpan - table.Columns.Count).Select(_ => string.Empty).ToArray());\ntable.AddRow(rowCells);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always AddColumn(s) to match the widest row before adding rows.","Sum each cell's span (TableCell.ColumnSpan else 1) and compare to table.Columns.Count.","When spans come from data, cap them: span = Math.Min(span, columns - otherCells).","Remember: fewer cells than columns is fine (auto-padded); only excess throws."],"tags":["table","column-span","row","invalid-operation","column-count-mismatch"],"backgroundTag":null,"analyzedSha":"0acc92fada6c42f13984e79c2b5f3d993bdfb099","analyzedAt":"2026-08-13T18:27:21.983Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}