{"record":{"id":"36c78f14bc022cf0","repo":"Humanizr/Humanizer","slug":"precision-must-be-greater-than-zero","errorCode":null,"errorMessage":"Precision must be greater than zero.","messagePattern":"Precision must be greater than zero\\.","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Humanizer/Bytes/ByteSizeExtensions.cs","lineNumber":503,"sourceCode":"    /// </summary>\n    /// <param name=\"input\">The byte quantity to humanize.</param>\n    /// <param name=\"precision\">The maximum number of non-zero parts to return.</param>\n    /// <param name=\"formatProvider\">The format provider to use. If null, the current culture is used.</param>\n    /// <param name=\"separator\">The separator to use between parts.</param>\n    /// <param name=\"toWords\">Uses unit words instead of symbols if true.</param>\n    /// <returns>The composite byte quantity.</returns>\n    /// <exception cref=\"ArgumentOutOfRangeException\"><paramref name=\"precision\"/> is less than one.</exception>\n    /// <exception cref=\"ArgumentNullException\"><paramref name=\"separator\"/> is null.</exception>\n    public static string HumanizeComposite(\n        this ByteSize input,\n        int precision = 2,\n        IFormatProvider? formatProvider = null,\n        string separator = \" \",\n        bool toWords = false)\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\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 isNegative = input.Bits < 0;\n        var remainingBits = isNegative\n            ? (ulong)(-(input.Bits + 1)) + 1\n            : (ulong)input.Bits;\n\n        if (remainingBits == 0)","sourceCodeStart":485,"sourceCodeEnd":521,"githubUrl":"https://github.com/Humanizr/Humanizer/blob/ffc2b77c0f30d2fb176875841424379319d0ae9b/src/Humanizer/Bytes/ByteSizeExtensions.cs#L485-L521","documentation":"Thrown by ByteSizeExtensions.HumanizeComposite when the precision argument is less than one. Precision controls the maximum number of non-zero parts (e.g. '1 GB 2 MB' = precision 2); zero or negative precision is meaningless and is rejected before any formatting begins.","triggerScenarios":"Calling HumanizeComposite(precision: 0), HumanizeComposite(precision: -1), or passing a computed precision that underflows to zero (e.g. a count minus a buffer).","commonSituations":"Binding precision to a user setting with no minimum, deriving precision from a list length that can be zero, or copy-pasting a default argument and zeroing it out.","solutions":["Clamp precision to at least 1 before calling: Math.Max(1, requestedPrecision).","Validate user-supplied precision at the input boundary and reject values below one.","Use the default (2) unless a specific part count is genuinely needed."],"exampleFix":"// before\nvar text = size.HumanizeComposite(precision: userPrecision);\n\n// after\nvar text = size.HumanizeComposite(precision: Math.Max(1, userPrecision));","handlingStrategy":"validation","validationCode":"if (precision < 1) throw new ArgumentOutOfRangeException(nameof(precision));","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Clamp precision to at least 1","Validate user-supplied precision at the boundary","Use the default (2) unless a specific part count is needed"],"tags":["bytesize","argument-validation","humanize","precision"],"backgroundTag":null,"analyzedSha":"ffc2b77c0f30d2fb176875841424379319d0ae9b","analyzedAt":"2026-08-13T21:42:34.584Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}