tui-cs/Terminal.Gui · error · ArgumentException
Steps must be greater than 0.
Error message
Steps must be greater than 0.
What it means
Thrown by the Gradient constructor when any value in the steps collection is less than 1. Steps define how many interpolated colors to generate between adjacent stops, so zero or negative steps are meaningless. It is an ArgumentException. Note a single step value is auto-expanded across all stop pairs when there are more than two stops.
Source
Thrown at Terminal.Gui/Drawing/Gradient.cs:79
{
_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");
}
_loop = loop;
Spectrum = GenerateGradient (_steps);
}
/// <summary>
/// Returns the color to use at the given part of the spectrum
/// </summary>
/// <param name="fraction">
/// Proportion of the way through the spectrum, must be between
/// 0 and 1 (inclusive). Returns the last color if <paramref name="fraction"/> is
/// <see cref="double.NaN"/>.View on GitHub (pinned to 2e47b11478)
Solutions
- Clamp each step to at least 1: steps = steps.Select(s => Math.Max(1, s)).
- Validate step values before constructing the Gradient.
- Ensure the source dimension used to derive steps is >= 2.
Example fix
// before
var g = new Gradient(stops, new[] { width - 1 });
// after
int step = Math.Max(1, width - 1);
var g = new Gradient(stops, new[] { step }); Defensive patterns
Strategy: validation
Validate before calling
steps = steps.Select(s => Math.Max(1, s)).ToList();
Type guard
static bool AllStepsPositive(IEnumerable<int> steps) => steps.All(s => s >= 1);
Try / catch
try { g = new Gradient(stops, steps); } catch (ArgumentException) { g = new Gradient(stops, Enumerable.Repeat(1, stops.Count()-1)); } Prevention
- Clamp step counts to a minimum of 1.
- Watch for size-derived step values that can be zero on tiny areas.
- Validate step values before constructing the Gradient.
When it happens
Trigger: Calling new Gradient(stops, new[] { 0 }), new Gradient(stops, new[] { -1 }), or a steps list where any element is <= 0.
Common situations: Computing step counts from sizes/dimensions that can be zero (e.g. width-1 on a 1-cell area), config providing 0, or arithmetic underflow.
Related errors
- At least one color stop must be provided.
- 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/740f25036cf15dd4.
Report an issue: GitHub.