{"record":{"id":"76722090afcb8caa","repo":"spectreconsole/spectre.console","slug":"column-span-must-be-at-least-1","errorCode":null,"errorMessage":"Column span must be at least 1.","messagePattern":"Column span must be at least 1\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Spectre.Console/Widgets/Table/TableCell.cs","lineNumber":46,"sourceCode":"    /// <summary>\n    /// Initializes a new instance of the <see cref=\"TableCell\"/> class.\n    /// </summary>\n    /// <param name=\"markup\">Markup text.</param>\n    public TableCell(string markup)\n        : this(new Markup(markup ?? string.Empty))\n    {\n    }\n\n    /// <summary>\n    /// Sets the number of columns this cell should span.\n    /// </summary>\n    /// <param name=\"span\">The number of columns to span.</param>\n    /// <returns>The same instance so that multiple calls can be chained.</returns>\n    public TableCell Span(int span)\n    {\n        if (span < 1)\n        {\n            throw new ArgumentException(\"Column span must be at least 1.\", nameof(span));\n        }\n\n        ColumnSpan = span;\n        return this;\n    }\n\n    /// <summary>\n    /// Implicitly converts a <see cref=\"string\"/> to a <see cref=\"TableCell\"/>.\n    /// </summary>\n    /// <param name=\"markup\">The markup text to convert.</param>\n    public static implicit operator TableCell(string markup)\n    {\n        return new TableCell(markup);\n    }\n\n    /// <inheritdoc/>\n    Measurement IRenderable.Measure(RenderOptions options, int maxWidth)\n    {","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/spectreconsole/spectre.console/blob/0acc92fada6c42f13984e79c2b5f3d993bdfb099/src/Spectre.Console/Widgets/Table/TableCell.cs#L28-L64","documentation":"TableCell.Span(int span) sets how many columns a body cell covers. The constructor defaults ColumnSpan to 1, and Span() rejects any value below 1 because a cell must occupy at least one column. Passing 0 or a negative number throws ArgumentException on the 'span' parameter.","triggerScenarios":"Calling cell.Span(0), cell.Span(-1), or any value < 1. Most common when span is computed (loop counters, column-remainder math, data-driven widths) and the computation can legally produce zero (e.g. last column, empty data range, Math.Max(0, ...)).","commonSituations":"Off-by-one when distributing a cell across remaining columns (e.g. columns - i evaluates to 0 on the final column); using Math.Max(0, x) instead of Math.Max(1, x); feeding a user/config value that can be 0; passing an int from a parsed config file with no lower-bound validation.","solutions":["Clamp the value before calling Span: cell.Span(Math.Max(1, computedSpan)).","If the cell should cover exactly one column, omit the Span() call entirely (default ColumnSpan is 1).","Guard the computed span and skip/merge the cell when it would be 0, rather than calling Span with it.","Validate external/config values at the boundary: if (value < 1) throw or default to 1."],"exampleFix":"// before\nvar cell = new TableCell(text).Span(columns - currentIndex); // 0 on last column\n\n// after\nvar span = Math.Max(1, columns - currentIndex);\nvar cell = new TableCell(text).Span(span);","handlingStrategy":"validation","validationCode":"if (span < 1) span = 1; // or throw at your boundary\ncell.Span(span);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Clamp any data-derived span with Math.Max(1, value) before calling Span().","Treat the default span (1) as the norm and only call Span() when you need > 1.","Validate external/config integers at the trust boundary with a minimum of 1."],"tags":["table","column-span","argument-validation","off-by-one"],"backgroundTag":null,"analyzedSha":"0acc92fada6c42f13984e79c2b5f3d993bdfb099","analyzedAt":"2026-08-13T18:27:21.983Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}