Humanizr/Humanizer · error · OverflowException
The result is outside the range supported by ByteSize.Bits.
Error message
The result is outside the range supported by ByteSize.Bits.
What it means
Thrown by ByteSize.AddUnit (the internal accumulator used during parsing of composite/multi-part input) when the running total plus the next parsed value produces a result that is non-finite or outside the supported byte range. It is an OverflowException rather than ArgumentOutOfRange because the failure arises from accumulation, not a single bad argument.
Source
Thrown at src/Humanizer/Bytes/ByteSize.cs:1820
{
throw new ArgumentOutOfRangeException(nameof(unitSystem), unitSystem, "Unknown byte-size unit system.");
}
}
static bool IsSupportedUnitValue(double value, double bytesPerUnit)
{
var bytes = value * bytesPerUnit;
return double.IsFinite(bytes) &&
bytes >= -BytesInPebibyte * 1024d &&
bytes < BytesInPebibyte * 1024d;
}
static ByteSize AddUnit(double current, double value, double bytesPerUnit)
{
var result = current + value;
if (!IsSupportedUnitValue(result, bytesPerUnit))
{
throw new OverflowException("The result is outside the range supported by ByteSize.Bits.");
}
return new(result * bytesPerUnit);
}
public static ByteSize Parse(string s) =>
Parse(s, null);
public static ByteSize Parse(string s, IFormatProvider? formatProvider)
{
ArgumentNullException.ThrowIfNull(s);
if (TryParse(s, formatProvider, out var result))
{
return result;
}
throw new FormatException("Value is not in the correct format");View on GitHub (pinned to ffc2b77c0f)
Solutions
- Prefer TryParse variants which return false instead of throwing on overflow during accumulation.
- Validate the input magnitude against the supported ceiling before parsing.
- Catch OverflowException at the trust boundary and surface a 'value too large' message.
Example fix
// before
var size = ByteSize.Parse(hugeCompositeInput);
// after
if (!ByteSize.TryParse(hugeCompositeInput, out var size))
{
throw new InvalidOperationException("Input exceeds the supported byte-size range.");
} Defensive patterns
Strategy: try-catch
Validate before calling
if (!ByteSize.TryParse(input, out var size))
throw new OverflowException("Input exceeds the supported byte-size range."); Try / catch
try { return ByteSize.Parse(input); }
catch (OverflowException) { throw new InvalidOperationException("Byte-size input is too large to represent."); } Prevention
- Prefer TryParse for aggregated/large inputs
- Validate magnitude against the supported ceiling first
- Catch OverflowException at the trust boundary
When it happens
Trigger: Parsing a multi-part byte-size expression whose components sum past the supported ceiling (BytesInPebibyte*1024), or accumulating many parts where each individual value passes IsSupportedUnitValue but the running total does not.
Common situations: Parsing aggregated strings like '1000 EB 1000 EB', or summing parsed fragments from telemetry in a loop where the total eventually exceeds the long-backed bit range.
Related errors
- Value is not in the correct format
- Unit token '{unit.Symbol}' does not belong to the selected b
- EiB is outside the range supported by ByteSize.Bits.
- A byte-size format can contain only one distinct unit token.
- Unable to protect the byte-size unit token.
AI-assisted analysis of Humanizr/Humanizer@ffc2b77c0f (2026-08-13).
Data as JSON: /api/errors/4fc6cdff621c71fe.
Report an issue: GitHub.