{"record":{"id":"e93171b7ceb78570","repo":"Humanizr/Humanizer","slug":"unknown-byte-size-unit-system-e93171","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/ByteSizeExtensions.cs","lineNumber":591,"sourceCode":"    /// <paramref name=\"unitSystem\"/> is not defined or <paramref name=\"precision\"/> is less than one.\n    /// </exception>\n    /// <exception cref=\"ArgumentNullException\"><paramref name=\"separator\"/> is <see langword=\"null\"/>.</exception>\n    public static string HumanizeCompositeWithUnitSystem(\n        this ByteSize input,\n        ByteSizeUnitSystem unitSystem,\n        int precision = 2,\n        IFormatProvider? formatProvider = null,\n        string separator = \" \",\n        bool toWords = false)\n    {\n        if (unitSystem == ByteSizeUnitSystem.Legacy)\n        {\n            return input.HumanizeComposite(precision, formatProvider, separator, toWords);\n        }\n\n        if (unitSystem is < ByteSizeUnitSystem.DecimalSi or > ByteSizeUnitSystem.BinaryIec)\n        {\n            throw new ArgumentOutOfRangeException(nameof(unitSystem), unitSystem, \"Unknown byte-size unit system.\");\n        }\n\n        if (precision < 1)\n        {\n            throw new ArgumentOutOfRangeException(nameof(precision), precision, \"Precision must be greater than zero.\");\n        }\n\n        ArgumentNullException.ThrowIfNull(separator);\n        formatProvider ??= CultureInfo.CurrentCulture;\n        var culture = formatProvider as CultureInfo;\n        if (culture is not null)\n        {\n            formatProvider = LocaleNumberFormattingOverrides.GetFormattingNumberFormat(culture);\n        }\n\n        var formatter = Configurator.GetFormatter(culture);\n        var builtInFormatter = formatter as DefaultFormatter;\n        if (builtInFormatter is not null &&","sourceCodeStart":573,"sourceCodeEnd":609,"githubUrl":"https://github.com/Humanizr/Humanizer/blob/ffc2b77c0f30d2fb176875841424379319d0ae9b/src/Humanizer/Bytes/ByteSizeExtensions.cs#L573-L609","documentation":"Thrown by ByteSizeExtensions.HumanizeCompositeWithUnitSystem when the unitSystem argument is neither Legacy (which is handled earlier and delegates to HumanizeComposite) nor within the [DecimalSi, BinaryIec] range. The method explicitly rejects undefined enum values before doing any work.","triggerScenarios":"Calling HumanizeCompositeWithUnitSystem with an undefined ByteSizeUnitSystem value (e.g. (ByteSizeUnitSystem)42), or forwarding a config/JSON-derived integer that does not map to a named member.","commonSituations":"Deserializing the enum from a source with different naming, casting an arbitrary integer, or a binding default that produced an out-of-range value.","solutions":["Constrain the value to a named member before calling; map unknowns to Legacy.","Validate with Enum.IsDefined at the API boundary.","Use ByteSizeUnitSystem.DecimalSi or BinaryIec explicitly when the system is known."],"exampleFix":"// before\nvar text = size.HumanizeCompositeWithUnitSystem((ByteSizeUnitSystem)configValue);\n\n// after\nvar system = Enum.IsDefined(typeof(ByteSizeUnitSystem), configValue)\n    ? (ByteSizeUnitSystem)configValue\n    : ByteSizeUnitSystem.Legacy;\nvar text = size.HumanizeCompositeWithUnitSystem(system);","handlingStrategy":"validation","validationCode":"if (!Enum.IsDefined(typeof(ByteSizeUnitSystem), system))\n    throw new ArgumentOutOfRangeException(nameof(system));","typeGuard":"static bool IsSupportedSystem(ByteSizeUnitSystem s) =>\n    s is ByteSizeUnitSystem.Legacy or ByteSizeUnitSystem.DecimalSi or ByteSizeUnitSystem.BinaryIec;","tryCatchPattern":null,"preventionTips":["Validate the enum at the API boundary","Map unknown values to Legacy","Avoid casting arbitrary integers to the enum"],"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"}