tui-cs/Terminal.Gui · error · ArgumentException
At least one color stop must be provided.
Error message
At least one color stop must be provided.
What it means
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.
Source
Thrown at Terminal.Gui/Drawing/Gradient.cs:66
/// <summary>
/// Creates a new instance of the <see cref="Gradient"/> class which hosts a <see cref="Spectrum"/>
/// of colors including all <paramref name="stops"/> and <paramref name="steps"/> interpolated colors
/// between each corresponding pair.
/// </summary>
/// <param name="stops">The colors to use in the spectrum (N)</param>
/// <param name="steps">
/// The number of colors to generate between each pair (must be N-1 numbers).
/// If only one step is passed then it is assumed to be the same distance for all pairs.
/// </param>
/// <param name="loop">True to duplicate the first stop and step so that the gradient repeats itself</param>
/// <exception cref="ArgumentException"></exception>
public Gradient (IEnumerable<Color> stops, IEnumerable<int> steps, bool loop = false)
{
_stops = stops.ToList ();
if (_stops.Count < 1)
{
throw new ArgumentException ("At least one color stop must be provided.");
}
_steps = steps.ToList ();
// If multiple colors and only 1 step assume same distance applies to all steps
if (_stops.Count > 2 && _steps.Count == 1)
{
_steps = Enumerable.Repeat (_steps.Single (), _stops.Count () - 1).ToList ();
}
if (_steps.Any (step => step < 1))
{
throw new ArgumentException ("Steps must be greater than 0.");
}
if (_steps.Count != _stops.Count - 1)
{
throw new ArgumentException ("Number of steps must be N-1");View on GitHub (pinned to 2e47b11478)
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.
Example fix
// before
var g = new Gradient(stops, steps);
// after
if (!stops.Any()) stops = new[] { Color.Black };
var g = new Gradient(stops, steps); Defensive patterns
Strategy: validation
Validate before calling
if (!stops.Any()) stops = new[] { defaultColor }; Type guard
static bool HasStops(IEnumerable<Color> stops) => stops.Any();
Try / catch
try { g = new Gradient(stops, steps); } catch (ArgumentException) { g = new Gradient(new[]{Color.Black}, new[]{1}); } Prevention
- 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.
When it happens
Trigger: Calling new Gradient(Array.Empty<Color>(), new[] { 1 }) or new Gradient(Enumerable.Empty<Color>(), ...).
Common situations: Dynamically building a stop list from data that turned out empty (filtered collection, empty config array, or a programmatic generator returning no colors).
Related errors
- Steps must be greater than 0.
- Number of steps must be N-1
- Fraction must be between 0 and 1.
- start must be greater than or equal to 0
- Provided text is too short to be any known color format.
AI-assisted analysis of tui-cs/Terminal.Gui@2e47b11478 (2026-08-13).
Data as JSON: /api/errors/778291f62f04f98b.
Report an issue: GitHub.