{"record":{"id":"2c3fe9c7b6d55025","repo":"Humanizr/Humanizer","slug":"the-value-must-be-finite-and-fit-the-range-support","errorCode":null,"errorMessage":"The value must be finite and fit the range supported by ByteSize.Bits.","messagePattern":"The value must be finite and fit the range supported by ByteSize\\.Bits\\.","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Humanizer/Bytes/ByteSize.cs","lineNumber":327,"sourceCode":"        new(value / (double)BitsInByte);\n\n    internal static ByteSize FromBytesAndBits(double bytes, long bits) =>\n        new(bytes, bits);\n\n    public static ByteSize FromBytes(double value) =>\n        new(value);\n\n    public static ByteSize FromKilobytes(double value) =>\n        new(value * BytesInKilobyte);\n\n    /// <summary>\n    /// Creates a byte size from a number of kibibytes.\n    /// </summary>\n    public static ByteSize FromKibibytes(double value)\n    {\n        if (!IsSupportedUnitValue(value, BytesInKibibyte))\n        {\n            throw new ArgumentOutOfRangeException(nameof(value), \"The value must be finite and fit the range supported by ByteSize.Bits.\");\n        }\n\n        return new(value * BytesInKibibyte);\n    }\n\n    public static ByteSize FromMegabytes(double value) =>\n        new(value * BytesInMegabyte);\n\n    /// <summary>\n    /// Creates a byte size from a number of mebibytes.\n    /// </summary>\n    public static ByteSize FromMebibytes(double value)\n    {\n        if (!IsSupportedUnitValue(value, BytesInMebibyte))\n        {\n            throw new ArgumentOutOfRangeException(nameof(value), \"The value must be finite and fit the range supported by ByteSize.Bits.\");\n        }\n","sourceCodeStart":309,"sourceCodeEnd":345,"githubUrl":"https://github.com/Humanizr/Humanizer/blob/ffc2b77c0f30d2fb176875841424379319d0ae9b/src/Humanizer/Bytes/ByteSize.cs#L309-L345","documentation":"Thrown by ByteSize.FromKibibytes(double) when the argument, multiplied by BytesInKibibyte (1024), produces a result that is not finite (NaN or Infinity) or falls outside the supported byte range of approximately ±1 exbibyte (specifically ±BytesInPebibyte * 1024). The IsSupportedUnitValue guard rejects overflow-prone or non-finite inputs before they corrupt the ByteSize struct.","triggerScenarios":"Calling ByteSize.FromKibibytes(double.NaN), ByteSize.FromKibibytes(double.PositiveInfinity), or a value so large that value * 1024 exceeds the supported range. For example, FromKibibytes(1e18) would overflow the supported bounds.","commonSituations":"A developer receives a size value from an external source (API, file system, user input) that is NaN, Infinity, or astronomically large, and passes it to FromKibibytes without validation. Also common when a division-by-zero upstream produces NaN that flows into this method.","solutions":["Validate that the input is finite (double.IsFinite) and within a reasonable range before calling FromKibibytes.","Use ByteSize.FromBytes or the unchecked kilobyte/megabyte factory methods if you need to bypass the range guard (note those methods do not validate).","Sanitize upstream calculations that might produce NaN or Infinity."],"exampleFix":"// before\nvar size = ByteSize.FromKibibytes(someExternalValue);\n\n// after\nif (!double.IsFinite(someExternalValue) ||\n    Math.Abs(someExternalValue) > 1e15)\n    throw new ArgumentException(\"Invalid kibibyte value\", nameof(someExternalValue));\nvar size = ByteSize.FromKibibytes(someExternalValue);","handlingStrategy":"validation","validationCode":"if (!double.IsFinite(value) || Math.Abs(value) > 1e15)\n    throw new ArgumentOutOfRangeException(nameof(value),\n        \"Value must be finite and within the supported kibibyte range.\");\nvar size = ByteSize.FromKibibytes(value);","typeGuard":"static bool IsValidByteSizeUnitValue(double value, double bytesPerUnit) =>\n    double.IsFinite(value * bytesPerUnit) &&\n    Math.Abs(value * bytesPerUnit) < 1024d * 1024 * 1024 * 1024 * 1024;","tryCatchPattern":null,"preventionTips":["Validate double.IsFinite before calling FromKibibytes to reject NaN and Infinity.","Sanitize upstream calculations that might produce NaN (e.g. division by zero).","Use ByteSize.FromBytes if you need to construct from an arbitrary double without the range guard."],"tags":["runtime","byte-size","argument-out-of-range","overflow","validation"],"backgroundTag":null,"analyzedSha":"ffc2b77c0f30d2fb176875841424379319d0ae9b","analyzedAt":"2026-08-13T21:42:34.584Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}