{"record":{"id":"6597fd450bda4e49","repo":"Humanizr/Humanizer","slug":"unknown-byte-size-unit-system","errorCode":null,"errorMessage":"Unknown byte-size unit system.","messagePattern":"Unknown byte-size unit system\\.","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Humanizer/Bytes/ByteSize.cs","lineNumber":1180,"sourceCode":"            result.Append(newValue);\n            searchStart = index + oldValue.Length;\n            index = CultureInfo.InvariantCulture.CompareInfo.IndexOf(\n                searchValue,\n                oldValue,\n                searchStart,\n                CompareOptions.OrdinalIgnoreCase);\n        }\n        while (index >= 0);\n\n        return result.Append(value, searchStart, value.Length - searchStart).ToString();\n    }\n\n    static SystemUnit[] GetUnits(ByteSizeUnitSystem unitSystem) =>\n        unitSystem switch\n        {\n            ByteSizeUnitSystem.DecimalSi => DecimalUnits,\n            ByteSizeUnitSystem.BinaryIec => BinaryUnits,\n            _ => throw new ArgumentOutOfRangeException(nameof(unitSystem), unitSystem, \"Unknown byte-size unit system.\")\n        };\n\n    static readonly SystemUnit[] DecimalUnits =\n    [\n        new(BytesInDecimalExabyte, \"EB\", DataUnit.DecimalExabyte),\n        new(BytesInDecimalPetabyte, \"PB\", DataUnit.DecimalPetabyte),\n        new(BytesInDecimalTerabyte, \"TB\", DataUnit.DecimalTerabyte),\n        new(BytesInDecimalGigabyte, \"GB\", DataUnit.DecimalGigabyte),\n        new(BytesInDecimalMegabyte, \"MB\", DataUnit.DecimalMegabyte),\n        new(BytesInDecimalKilobyte, \"kB\", DataUnit.DecimalKilobyte)\n    ];\n\n    static readonly SystemUnit[] BinaryUnits =\n    [\n        new(BytesInPebibyte, \"PiB\", DataUnit.BinaryPebibyte),\n        new(BytesInTebibyte, \"TiB\", DataUnit.BinaryTebibyte),\n        new(BytesInGibibyte, \"GiB\", DataUnit.BinaryGibibyte),\n        new(BytesInMebibyte, \"MiB\", DataUnit.BinaryMebibyte),","sourceCodeStart":1162,"sourceCodeEnd":1198,"githubUrl":"https://github.com/Humanizr/Humanizer/blob/ffc2b77c0f30d2fb176875841424379319d0ae9b/src/Humanizer/Bytes/ByteSize.cs#L1162-L1198","documentation":"Thrown by ByteSize.GetUnits(ByteSizeUnitSystem) for any value that is not DecimalSi or BinaryIec. GetUnits is the internal lookup that maps a unit system to its symbol array; the default arm of the switch rejects undefined enum values rather than returning null.","triggerScenarios":"Calling a formatting overload that resolves units through GetUnits with a ByteSizeUnitSystem value outside {DecimalSi, BinaryIec} — including an uninitialized/default enum (0 if 0 is not a named member) or a future/invalid cast integer.","commonSituations":"Casting an arbitrary integer to ByteSizeUnitSystem, deserializing an enum from JSON where the source used a different naming scheme, or passing ByteSizeUnitSystem.Legacy into a path that does not special-case Legacy before GetUnits.","solutions":["Constrain the value to DecimalSi or BinaryIec before formatting; handle Legacy at the call site before reaching GetUnits.","Validate the enum with Enum.IsDefined or an explicit range check upstream.","When deserializing, map unknown values to a default system rather than forwarding them."],"exampleFix":"// before\nvar units = GetUnits((ByteSizeUnitSystem)userChoice);\n\n// after\nvar system = userChoice switch\n{\n    0 => ByteSizeUnitSystem.DecimalSi,\n    1 => ByteSizeUnitSystem.BinaryIec,\n    _ => ByteSizeUnitSystem.Legacy\n};\nif (system == ByteSizeUnitSystem.Legacy) { /* use legacy path */ }","handlingStrategy":"validation","validationCode":"static ByteSizeUnitSystem NormalizeSystem(ByteSizeUnitSystem value) =>\n    value is ByteSizeUnitSystem.DecimalSi or ByteSizeUnitSystem.BinaryIec\n        ? value\n        : throw new ArgumentOutOfRangeException(nameof(value));","typeGuard":"static bool IsSupportedUnitSystem(ByteSizeUnitSystem s) =>\n    s is ByteSizeUnitSystem.DecimalSi or ByteSizeUnitSystem.BinaryIec;","tryCatchPattern":"try { return GetUnits(system); }\ncatch (ArgumentOutOfRangeException) { throw new ArgumentException(\"Use DecimalSi or BinaryIec.\", nameof(system)); }","preventionTips":["Constrain the enum to DecimalSi/BinaryIec before formatting","Handle Legacy at the call site, not inside GetUnits","Validate deserialized enums with Enum.IsDefined"],"tags":["bytesize","unit-system","enum-validation","argumentoutofrange"],"backgroundTag":null,"analyzedSha":"ffc2b77c0f30d2fb176875841424379319d0ae9b","analyzedAt":"2026-08-13T21:42:34.584Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}