{"record":{"id":"778291f62f04f98b","repo":"tui-cs/Terminal.Gui","slug":"at-least-one-color-stop-must-be-provided","errorCode":null,"errorMessage":"At least one color stop must be provided.","messagePattern":"At least one color stop must be provided\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Terminal.Gui/Drawing/Gradient.cs","lineNumber":66,"sourceCode":"    /// <summary>\n    ///     Creates a new instance of the <see cref=\"Gradient\"/> class which hosts a <see cref=\"Spectrum\"/>\n    ///     of colors including all <paramref name=\"stops\"/> and <paramref name=\"steps\"/> interpolated colors\n    ///     between each corresponding pair.\n    /// </summary>\n    /// <param name=\"stops\">The colors to use in the spectrum (N)</param>\n    /// <param name=\"steps\">\n    ///     The number of colors to generate between each pair (must be N-1 numbers).\n    ///     If only one step is passed then it is assumed to be the same distance for all pairs.\n    /// </param>\n    /// <param name=\"loop\">True to duplicate the first stop and step so that the gradient repeats itself</param>\n    /// <exception cref=\"ArgumentException\"></exception>\n    public Gradient (IEnumerable<Color> stops, IEnumerable<int> steps, bool loop = false)\n    {\n        _stops = stops.ToList ();\n\n        if (_stops.Count < 1)\n        {\n            throw new ArgumentException (\"At least one color stop must be provided.\");\n        }\n\n        _steps = steps.ToList ();\n\n        // If multiple colors and only 1 step assume same distance applies to all steps\n        if (_stops.Count > 2 && _steps.Count == 1)\n        {\n            _steps = Enumerable.Repeat (_steps.Single (), _stops.Count () - 1).ToList ();\n        }\n\n        if (_steps.Any (step => step < 1))\n        {\n            throw new ArgumentException (\"Steps must be greater than 0.\");\n        }\n\n        if (_steps.Count != _stops.Count - 1)\n        {\n            throw new ArgumentException (\"Number of steps must be N-1\");","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/tui-cs/Terminal.Gui/blob/2e47b11478db083499917f2ad27c34d30efb0df1/Terminal.Gui/Drawing/Gradient.cs#L48-L84","documentation":"Thrown by the Gradient constructor when the stops collection contains fewer than one color. A gradient requires at least one stop to produce a spectrum. It is an ArgumentException. With zero stops there is nothing to interpolate, so the constructor refuses to build an invalid Gradient.","triggerScenarios":"Calling new Gradient(Array.Empty<Color>(), new[] { 1 }) or new Gradient(Enumerable.Empty<Color>(), ...).","commonSituations":"Dynamically building a stop list from data that turned out empty (filtered collection, empty config array, or a programmatic generator returning no colors).","solutions":["Guard the caller: if (!stops.Any()) return; or supply a default stop.","Provide at least one Color in the stops collection.","Validate the source data before constructing the Gradient."],"exampleFix":"// before\nvar g = new Gradient(stops, steps);\n\n// after\nif (!stops.Any()) stops = new[] { Color.Black };\nvar g = new Gradient(stops, steps);","handlingStrategy":"validation","validationCode":"if (!stops.Any()) stops = new[] { defaultColor };","typeGuard":"static bool HasStops(IEnumerable<Color> stops) => stops.Any();","tryCatchPattern":"try { g = new Gradient(stops, steps); } catch (ArgumentException) { g = new Gradient(new[]{Color.Black}, new[]{1}); }","preventionTips":["Guarantee at least one stop before constructing a Gradient.","Treat empty source collections as a degenerate case at the data boundary.","Supply a sensible default color when the list is empty."],"tags":["gradient","drawing","validation","argument-exception"],"backgroundTag":null,"analyzedSha":"2e47b11478db083499917f2ad27c34d30efb0df1","analyzedAt":"2026-08-13T19:20:08.826Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}