{"record":{"id":"952cfc8ab04a6358","repo":"Humanizr/Humanizer","slug":"unrecognized-number-word-unrecognizedword-952cfc","errorCode":null,"errorMessage":"Unrecognized number word: {unrecognizedWord}","messagePattern":"Unrecognized number word: (.+?)","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Humanizer/Localisation/WordsToNumber/TokenMapWordsToNumberConverter.cs","lineNumber":31,"sourceCode":"{\n    const int MaxCompactGluedScaleCountLength = 96;\n    const int MaxCompactGluedScaleTokenCount = 16;\n    const int MaxCompactGluedScaleStatesPerPosition = 128;\n    const int MaxGluedScaleDepth = 8;\n\n    readonly TokenMapWordsToNumberRules rules = rules;\n    readonly FrozenDictionary<string, long>? exactOrdinalMap = rules.ExactOrdinalMap;\n    readonly FrozenDictionary<string, long>? ordinalScaleMap = rules.OrdinalScaleMap;\n    readonly FrozenDictionary<string, long>? gluedOrdinalScaleSuffixes = rules.GluedOrdinalScaleSuffixes;\n    readonly FrozenDictionary<string, long>? gluedScaleSuffixes = rules.GluedScaleSuffixes;\n    Dictionary<char, List<CompactGluedScaleToken>>? compactGluedScaleTokensByFirstCharacter;\n\n    /// <inheritdoc />\n    public override long Convert(string words)\n    {\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 &&","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/Humanizr/Humanizer/blob/ffc2b77c0f30d2fb176875841424379319d0ae9b/src/Humanizer/Localisation/WordsToNumber/TokenMapWordsToNumberConverter.cs#L13-L49","documentation":"TokenMapWordsToNumberConverter.Convert throws this ArgumentException at line 31 when TryConvert cannot map the phrase under the token-map grammar (the most common English-style converter). It supports optional invariant-integer fast input, exact/glued ordinal maps, and compact glued-scale tokens. Only Convert raises it; the Try overloads return false with the unrecognized token.","triggerScenarios":"Calling ToNumber with tokens absent from the cardinal/ordinal/glued maps and not a bare integer (when AllowInvariantIntegerInput is on). Fires at line 31 when TryConvert returns false.","commonSituations":"The default English converter rejecting foreign or misspelled words; free-form user text; ordinals fed to the integer path; punctuation or case the normalizer does not fold.","solutions":["Switch to TryToNumber(words, out var n, culture, out var bad) and handle false.","Use bad to locate the offending token and fix the input.","For numeric digit strings, rely on the invariant-integer fast path if AllowInvariantIntegerInput is enabled for the locale.","Confirm the phrase's language matches the culture (registry falls back to English for unsupported locales)."],"exampleFix":"// before\nvar n = \"twenty banana\".ToNumber(CultureInfo.GetCultureInfo(\"en\"));\n// after\nif (\"twenty banana\".TryToNumber(out var n, CultureInfo.GetCultureInfo(\"en\"), out var bad))\n    Use(n);\nelse\n    Warn($\"unrecognized token: {bad}\");","handlingStrategy":"validation","validationCode":"if (!words.TryToNumber(out var n, culture, out var unrecognized))\n    return Result.Fail($\"unrecognized token: {unrecognized}\");\nreturn Result.Ok(n);","typeGuard":null,"tryCatchPattern":"try { var n = words.ToNumber(culture); }\ncatch (ArgumentException ex) when (ex.Message.StartsWith(\"Unrecognized number word\"))\n    { /* handle */ }","preventionTips":["Use TryToNumber for untrusted input.","Match culture to phrase language; remember unsupported locales fall back to English.","For digit strings, rely on the invariant-integer fast path where allowed.","Pre-clean input (trim, collapse spaces)."],"tags":["words-to-number","token-map","argumentexception","parsing","localization"],"backgroundTag":null,"analyzedSha":"ffc2b77c0f30d2fb176875841424379319d0ae9b","analyzedAt":"2026-08-13T21:42:34.584Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}