{"record":{"id":"33adaac11473463b","repo":"Humanizr/Humanizer","slug":"specified-argument-was-out-of-the-range-of-valid-v","errorCode":null,"errorMessage":"Specified argument was out of the range of valid values. (Parameter 'items')","messagePattern":"Specified argument was out of the range of valid values\\. \\(Parameter 'items'\\)","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Humanizer/ArticlePrefixSort.cs","lineNumber":17,"sourceCode":"namespace Humanizer;\n\n/// <summary>\n/// Contains methods for removing, appending and prepending article prefixes for sorting strings ignoring the article.\n/// </summary>\npublic static class EnglishArticle\n{\n    /// <summary>\n    /// Removes the prefixed article and appends it to the same string.\n    /// </summary>\n    /// <param name=\"items\">The input array of strings</param>\n    /// <returns>Sorted string array</returns>\n    public static string[] AppendArticlePrefix(string[] items)\n    {\n        if (items.Length == 0)\n        {\n            throw new ArgumentOutOfRangeException(nameof(items));\n        }\n\n        var transformed = new string[items.Length];\n\n        for (var i = 0; i < items.Length; i++)\n        {\n            var item = items[i]\n                .AsSpan();\n            if (TryGetArticlePrefixLength(item, out var articleLength))\n            {\n                var removed = item[articleLength..]\n                    .TrimStart();\n                var article = item[..articleLength];\n                transformed[i] = $\"{removed} {article}\";\n            }\n            else\n            {\n                transformed[i] = item","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/Humanizr/Humanizer/blob/ffc2b77c0f30d2fb176875841424379319d0ae9b/src/Humanizer/ArticlePrefixSort.cs#L1-L35","documentation":"Thrown by EnglishArticle.AppendArticlePrefix when the input string array is empty (items.Length == 0). The method is designed to sort article-prefixed strings; an empty array has nothing to sort so Humanizer treats it as a programming error and throws ArgumentOutOfRangeException with the parameter name 'items'.","triggerScenarios":"Calling EnglishArticle.AppendArticlePrefix(items) where items is a zero-length string array. This typically happens when the array was constructed from a filtered or split result that produced no elements.","commonSituations":"A developer splits a string by a delimiter and passes the result to AppendArticlePrefix without checking for emptiness. Or a LINQ query that filters a collection returns zero items and the result is passed directly.","solutions":["Check items.Length > 0 before calling AppendArticlePrefix.","If an empty input is a valid no-op in your context, return an empty array early instead of calling the method.","Ensure the upstream data source (split, filter, query) is not unexpectedly empty."],"exampleFix":"// before\nvar sorted = EnglishArticle.AppendArticlePrefix(titles.ToArray());\n\n// after\nif (titles.Count == 0)\n    return Array.Empty<string>();\nvar sorted = EnglishArticle.AppendArticlePrefix(titles.ToArray());","handlingStrategy":"validation","validationCode":"if (items is null || items.Length == 0)\n    return Array.Empty<string>();\nreturn EnglishArticle.AppendArticlePrefix(items);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always check items.Length > 0 before calling AppendArticlePrefix.","Handle the empty case as a no-op in the calling code rather than relying on the exception.","Guard upstream data sources (split, filter, query) against returning empty collections."],"tags":["runtime","english-article","argument-out-of-range","validation"],"backgroundTag":null,"analyzedSha":"ffc2b77c0f30d2fb176875841424379319d0ae9b","analyzedAt":"2026-08-13T21:42:34.584Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}