{"record":{"id":"7843b76d5c88215a","repo":"Humanizr/Humanizer","slug":"input-words-cannot-be-empty-7843b7","errorCode":null,"errorMessage":"Input words cannot be empty.","messagePattern":"Input words cannot be empty\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Humanizer/Localisation/WordsToNumber/EastAsianPositionalWordsToNumberConverter.cs","lineNumber":30,"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        var normalized = words.Replace(\" \", string.Empty).Trim();\n        var negative = false;\n\n        foreach (var negativePrefix in profile.NegativePrefixes)\n        {\n            if (!normalized.StartsWith(negativePrefix, StringComparison.Ordinal))\n            {\n                continue;\n            }\n\n            normalized = normalized[negativePrefix.Length..];\n            negative = true;\n            break;\n        }\n\n        // Exact ordinals are checked before stripping ordinal affixes because some locales encode","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/Humanizr/Humanizer/blob/ffc2b77c0f30d2fb176875841424379319d0ae9b/src/Humanizer/Localisation/WordsToNumber/EastAsianPositionalWordsToNumberConverter.cs#L12-L48","documentation":"This ArgumentException is thrown inside EastAsianPositionalWordsToNumberConverter.TryConvert when the input is null, empty, or whitespace. It throws from the Try-variant, so TryToNumber will throw rather than return false on blank input. The converter has no tokens to match against an empty string, so the guard prevents a meaningless parse.","triggerScenarios":"Calling ToNumber or TryToNumber with null, string.Empty, or whitespace-only input on a locale backed by EastAsianPositionalWordsToNumberConverter.","commonSituations":"Unvalidated text from user input or deserialized data; strings that became empty after trimming; optional fields that were not populated in a payload.","solutions":["Check string.IsNullOrWhiteSpace(words) before calling either API.","Return a default or skip the call for blank input at the boundary.","Use nullable reference types to surface null propagation at compile time."],"exampleFix":"// before\nlong value = text.ToNumber(new CultureInfo(\"zh\"));\n\n// after\nif (string.IsNullOrWhiteSpace(text))\n    return 0;\nlong value = text.ToNumber(new CultureInfo(\"zh\"));","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(words))\n    return 0;\nreturn words.ToNumber(culture);","typeGuard":"static bool IsNonEmpty(string? words) =>\n    !string.IsNullOrWhiteSpace(words);","tryCatchPattern":"// TryToNumber also throws on empty — guard before calling\ntry\n{\n    return words.ToNumber(new CultureInfo(\"zh\"));\n}\ncatch (ArgumentException ex) when (ex.Message.Contains(\"cannot be empty\"))\n{\n    return 0;\n}","preventionTips":["Always guard with string.IsNullOrWhiteSpace before calling ToNumber or TryToNumber.","Handle blank input as a business decision at the call site.","Enable nullable reference types to catch null propagation at compile time.","Validate at the trust boundary before data reaches the parser."],"tags":["argumentexception","words-to-number","east-asian","null-empty-input","validation"],"backgroundTag":null,"analyzedSha":"ffc2b77c0f30d2fb176875841424379319d0ae9b","analyzedAt":"2026-08-13T21:42:34.584Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}