{"record":{"id":"e7a14dd8e4e85b27","repo":"Humanizr/Humanizer","slug":"input-words-cannot-be-empty-e7a14d","errorCode":null,"errorMessage":"Input words cannot be empty.","messagePattern":"Input words cannot be empty\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Humanizer/Localisation/WordsToNumber/TokenMapWordsToNumberConverter.cs","lineNumber":46,"sourceCode":"    {\n        if (!TryConvert(words, out var parsedValue, out var unrecognizedWord))\n        {\n            throw new ArgumentException($\"Unrecognized number word: {unrecognizedWord}\");\n        }\n\n        return parsedValue;\n    }\n\n    /// <inheritdoc />\n    public override bool TryConvert(string words, out long parsedValue) =>\n        TryConvert(words, out parsedValue, out _);\n\n    /// <inheritdoc />\n    public override bool TryConvert(string words, out long parsedValue, out string? unrecognizedWord)\n    {\n        if (string.IsNullOrWhiteSpace(words))\n        {\n            throw new ArgumentException(\"Input words cannot be empty.\");\n        }\n\n        if (rules.AllowInvariantIntegerInput &&\n            long.TryParse(words.Trim(), NumberStyles.Integer, CultureInfo.InvariantCulture, out parsedValue))\n        {\n            unrecognizedWord = null;\n            return true;\n        }\n\n        var normalizedSource = words.Trim();\n        var negative = false;\n\n        foreach (var negativePrefix in rules.NegativePrefixes)\n        {\n            if (!normalizedSource.StartsWith(negativePrefix, StringComparison.Ordinal))\n            {\n                continue;\n            }","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/Humanizr/Humanizer/blob/ffc2b77c0f30d2fb176875841424379319d0ae9b/src/Humanizer/Localisation/WordsToNumber/TokenMapWordsToNumberConverter.cs#L28-L64","documentation":"TokenMapWordsToNumberConverter.TryConvert throws this ArgumentException at line 46 for null, empty, or whitespace input. Because it is inside the Try overload, both ToNumber and TryToNumber throw on empty phrases; the invariant-integer fast path runs only after this guard.","triggerScenarios":"Passing null, string.Empty, or whitespace to any number method on a token-map locale (including the default English fallback). The IsNullOrWhiteSpace check at line 45 fires first.","commonSituations":"Blank UI fields, trimmed-to-empty values, unvalidated external input, empty substitution for missing data; hitting this via the English fallback when the requested locale is unsupported and the input was empty.","solutions":["Guard with !string.IsNullOrWhiteSpace(words) before any number call.","Handle blank as a caller-side condition.","Normalize upstream so empty never reaches the converter."],"exampleFix":"// before\n\"\".TryToNumber(out var n, CultureInfo.GetCultureInfo(\"en\"));\n// after\nif (!string.IsNullOrWhiteSpace(input) && input.TryToNumber(out var n, culture))\n    Use(n);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(words))\n    return Result.Skip();\nvar ok = words.TryToNumber(out var n, culture);","typeGuard":null,"tryCatchPattern":"try { var n = words.ToNumber(culture); }\ncatch (ArgumentException ex) when (ex.Message == \"Input words cannot be empty.\")\n    { /* blank input */ }","preventionTips":["Guard IsNullOrWhiteSpace before number-word calls (this fires for the English fallback too).","Treat blank input as a caller condition.","Centralize empty-input handling."],"tags":["words-to-number","token-map","input-validation","argumentexception","parsing"],"backgroundTag":null,"analyzedSha":"ffc2b77c0f30d2fb176875841424379319d0ae9b","analyzedAt":"2026-08-13T21:42:34.584Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}