{"record":{"id":"23d0336084af217a","repo":"spectreconsole/spectre.console","slug":"must-be-1","errorCode":null,"errorMessage":"Must be > 1","messagePattern":"Must be > 1","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Spectre.Console/Widgets/Canvas.cs","lineNumber":51,"sourceCode":"    /// </summary>\n    public bool Scale { get; set; } = true;\n\n    /// <summary>\n    /// Gets or sets the pixel width.\n    /// </summary>\n    [Obsolete(\"Not used anymore. Will be removed in future update.\")]\n    public int PixelWidth { get; set; } = 2;\n\n    /// <summary>\n    /// Initializes a new instance of the <see cref=\"Canvas\"/> class.\n    /// </summary>\n    /// <param name=\"width\">The canvas width.</param>\n    /// <param name=\"height\">The canvas height.</param>\n    public Canvas(int width, int height)\n    {\n        if (width < 1)\n        {\n            throw new ArgumentException(\"Must be > 1\", nameof(width));\n        }\n\n        if (height < 1)\n        {\n            throw new ArgumentException(\"Must be > 1\", nameof(height));\n        }\n\n        Width = width;\n        Height = height;\n\n        _pixels = new Color?[Width, Height];\n    }\n\n    /// <summary>\n    /// Sets a pixel with the specified color in the canvas at the specified location.\n    /// </summary>\n    /// <param name=\"x\">The X coordinate for the pixel.</param>\n    /// <param name=\"y\">The Y coordinate for the pixel.</param>","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/spectreconsole/spectre.console/blob/0acc92fada6c42f13984e79c2b5f3d993bdfb099/src/Spectre.Console/Widgets/Canvas.cs#L33-L69","documentation":"Thrown by the Canvas constructor when the width argument is less than 1. The message text 'Must be > 1' is misleading: the guard is 'width < 1', so the true minimum is 1 (i.e. >= 1). The library needs a positive width to allocate the internal _pixels Color?[,] array.","triggerScenarios":"Instantiating 'new Canvas(width, height)' where width is 0, negative, or derived from an uninitialized/zeroed variable.","commonSituations":"Reading canvas dimensions from config or user input that defaults to 0, calculating width from a console size that returned 0, or passing a computed width that underflows.","solutions":["Ensure the width argument is >= 1 before constructing the Canvas.","Clamp computed width values to a minimum of 1 using Math.Max(1, width).","Validate input from config/UI before passing to the Canvas constructor."],"exampleFix":"// before\nvar canvas = new Canvas(consoleWidth, height); // consoleWidth could be 0\n\n// after\nvar canvas = new Canvas(Math.Max(1, consoleWidth), height);","handlingStrategy":"validation","validationCode":"if (width < 1) throw new ArgumentOutOfRangeException(nameof(width), \"Canvas width must be >= 1\");\nvar canvas = new Canvas(width, height);","typeGuard":"static bool IsValidCanvasDimension(int value) => value >= 1;","tryCatchPattern":null,"preventionTips":["Clamp externally-sourced dimensions with Math.Max(1, value).","Validate terminal size detection results before passing to Canvas."],"tags":["canvas","argument-validation","constructor","spectre-console"],"backgroundTag":null,"analyzedSha":"0acc92fada6c42f13984e79c2b5f3d993bdfb099","analyzedAt":"2026-08-13T18:27:21.983Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}