tui-cs/Terminal.Gui · error · ColorParseException
Value was not composed entirely of decimal digits.
Error message
Value was not composed entirely of decimal digits.
What it means
Thrown inside ParseRgbaFormat when an rgb()/rgba() string contains 4 comma-separated values but the alpha (4th) component is not composed entirely of ASCII decimal digits. It is a ColorParseException whose BadValue is the alpha substring and BadValueName is "A". This pinpoints the alpha channel as the offending component.
Source
Thrown at Terminal.Gui/Drawing/Color/Color.Formatting.cs:390
return new Color (int.Parse (rSpan), int.Parse (gSpan), int.Parse (bSpan));
}
case 4:
{
// rgba(r,g,b,a)
ParseRgbValues (
in valuesSubstring,
in valueRanges,
in originalString,
out ReadOnlySpan<char> rSpan,
out ReadOnlySpan<char> gSpan,
out ReadOnlySpan<char> bSpan
);
ReadOnlySpan<char> aSpan = valuesSubstring [valueRanges [3]];
if (!aSpan.IsAllAsciiDigits ())
{
throw new ColorParseException (
in originalString,
"Value was not composed entirely of decimal digits.",
in aSpan,
nameof (A)
);
}
return new Color (int.Parse (rSpan), int.Parse (gSpan), int.Parse (bSpan), int.Parse (aSpan));
}
default:
throw new ColorParseException (
in originalString,
$"Wrong number of values. Expected 3 or 4 decimal integers. Got {rangeCount}.",
in originalString
);
}
[Pure]View on GitHub (pinned to 2e47b11478)
Solutions
- Ensure the alpha value is a non-negative integer string of digits only.
- If your source alpha is a 0..1 float, convert it to 0..255 integer first.
- Use Color.TryParse to catch the malformed rgba input.
Example fix
// before
Color c = Color.Parse($"rgb({r},{g},{b},{alphaFloat})");
// after
int alphaByte = (int)Math.Round(alphaFloat * 255);
Color c = Color.Parse($"rgb({r},{g},{b},{alphaByte})"); Defensive patterns
Strategy: validation
Validate before calling
string a = alphaSpan.ToString(); if (!a.AsSpan().IsAllAsciiDigits()) return fallbackColor;
Type guard
static bool IsValidAlphaComponent(string s) => s.AsSpan().IsAllAsciiDigits() && int.Parse(s) is >= 0 and <= 255;
Try / catch
try { c = Color.Parse($"rgb({r},{g},{b},{a})"); } catch (ColorParseException ex) { /* ex.BadValueName == "A" */ c = fallback; } Prevention
- Express alpha as an integer 0..255, not a 0..1 float.
- Avoid negative or hex alpha values inside rgb().
- Use Color.TryParse for user-built rgb strings.
When it happens
Trigger: Passing "rgb(10,20,30,-5)" (negative sign is not a digit), "rgb(10,20,30,0x10)" (hex), or "rgb(10,20,30,2.5)" (decimal point). Only unsigned integer decimals are accepted.
Common situations: Passing alpha as a float (common in CSS where alpha is 0..1), negative values, or hex notation inside an rgb() string.
Related errors
- Color hex string {hexString} was not in a supported format
- Wrong number of values. Expected 3 or 4 decimal integers. Go
- The text provided consisted of only whitespace characters.
- Text was too short to be any possible supported format.
- Text did not match any expected format.
AI-assisted analysis of tui-cs/Terminal.Gui@2e47b11478 (2026-08-13).
Data as JSON: /api/errors/f4af8f82482379d1.
Report an issue: GitHub.