{"record":{"id":"4fc6cdff621c71fe","repo":"Humanizr/Humanizer","slug":"the-result-is-outside-the-range-supported-by-bytes","errorCode":null,"errorMessage":"The result is outside the range supported by ByteSize.Bits.","messagePattern":"The result is outside the range supported by ByteSize\\.Bits\\.","errorType":"exception","errorClass":"OverflowException","httpStatus":null,"severity":"error","filePath":"src/Humanizer/Bytes/ByteSize.cs","lineNumber":1820,"sourceCode":"        {\n            throw new ArgumentOutOfRangeException(nameof(unitSystem), unitSystem, \"Unknown byte-size unit system.\");\n        }\n    }\n\n    static bool IsSupportedUnitValue(double value, double bytesPerUnit)\n    {\n        var bytes = value * bytesPerUnit;\n        return double.IsFinite(bytes) &&\n            bytes >= -BytesInPebibyte * 1024d &&\n            bytes < BytesInPebibyte * 1024d;\n    }\n\n    static ByteSize AddUnit(double current, double value, double bytesPerUnit)\n    {\n        var result = current + value;\n        if (!IsSupportedUnitValue(result, bytesPerUnit))\n        {\n            throw new OverflowException(\"The result is outside the range supported by ByteSize.Bits.\");\n        }\n\n        return new(result * bytesPerUnit);\n    }\n\n    public static ByteSize Parse(string s) =>\n        Parse(s, null);\n\n    public static ByteSize Parse(string s, IFormatProvider? formatProvider)\n    {\n        ArgumentNullException.ThrowIfNull(s);\n\n        if (TryParse(s, formatProvider, out var result))\n        {\n            return result;\n        }\n\n        throw new FormatException(\"Value is not in the correct format\");","sourceCodeStart":1802,"sourceCodeEnd":1838,"githubUrl":"https://github.com/Humanizr/Humanizer/blob/ffc2b77c0f30d2fb176875841424379319d0ae9b/src/Humanizer/Bytes/ByteSize.cs#L1802-L1838","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nvar size = ByteSize.Parse(hugeCompositeInput);\n\n// after\nif (!ByteSize.TryParse(hugeCompositeInput, out var size))\n{\n    throw new InvalidOperationException(\"Input exceeds the supported byte-size range.\");\n}","handlingStrategy":"try-catch","validationCode":"if (!ByteSize.TryParse(input, out var size))\n    throw new OverflowException(\"Input exceeds the supported byte-size range.\");","typeGuard":null,"tryCatchPattern":"try { return ByteSize.Parse(input); }\ncatch (OverflowException) { throw new InvalidOperationException(\"Byte-size input is too large to represent.\"); }","preventionTips":["Prefer TryParse for aggregated/large inputs","Validate magnitude against the supported ceiling first","Catch OverflowException at the trust boundary"],"tags":["bytesize","parsing","numeric-overflow","overflowexception"],"backgroundTag":null,"analyzedSha":"ffc2b77c0f30d2fb176875841424379319d0ae9b","analyzedAt":"2026-08-13T21:42:34.584Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}