Humanizr/Humanizer · error · ArgumentException
Unrecognized number word: {unrecognizedWord}
Error message
Unrecognized number word: {unrecognizedWord} What it means
LinkingAffixWordsToNumberConverter.Convert throws this ArgumentException after TryConvert reports the first token it could not map. It serves languages whose compounds embed teen stems or joined cardinal suffixes, so a token outside the locale's cardinal/linked-suffix map is unrecoverable. Only the throwing Convert path raises it; TryConvert returns false with the offending token in the out parameter.
Source
Thrown at src/Humanizer/Localisation/WordsToNumber/LinkingAffixWordsToNumberConverter.cs:16
namespace Humanizer;
/// <summary>
/// Parses languages that use linking affixes inside compounds, such as embedded teen stems or
/// joined suffixes on cardinal tokens.
/// </summary>
internal class LinkingAffixWordsToNumberConverter(LinkingAffixWordsToNumberProfile profile) : GenderlessWordsToNumberConverter
{
readonly LinkingAffixWordsToNumberProfile profile = profile;
/// <inheritdoc />
public override long Convert(string words)
{
if (!TryConvert(words, out var parsedValue, out var unrecognizedWord))
{
throw new ArgumentException($"Unrecognized number word: {unrecognizedWord}");
}
return parsedValue;
}
/// <inheritdoc />
public override bool TryConvert(string words, out long parsedValue) =>
TryConvert(words, out parsedValue, out _);
/// <inheritdoc />
public override bool TryConvert(string words, out long parsedValue, out string? unrecognizedWord)
{
if (string.IsNullOrWhiteSpace(words))
{
throw new ArgumentException("Input words cannot be empty.");
}
var normalized = TokenMapWordsToNumberNormalizer.Normalize(View on GitHub (pinned to ffc2b77c0f)
Solutions
- Switch from ToNumber to TryToNumber(words, out var n, culture, out var unrecognized) and handle the false return.
- Inspect the reported unrecognizedWord to find the misspelled or foreign token and correct the input.
- Confirm the CultureInfo passed matches the language of the phrase (registry falls back to English for unsupported locales).
- Pre-clean input (trim, collapse spaces, replace typographic quotes) before parsing.
Example fix
// before
var n = "twenty banana".ToNumber(CultureInfo.GetCultureInfo("en"));
// after
if ("twenty banana".TryToNumber(out var n, CultureInfo.GetCultureInfo("en"), out var bad))
Console.WriteLine(n);
else
Console.WriteLine($"bad token: {bad}"); Defensive patterns
Strategy: validation
Validate before calling
// Use the non-throwing overload; it reports the first bad token.
if (!words.TryToNumber(out var n, culture, out var unrecognized))
return Result.Fail($"unrecognized token: {unrecognized}");
return Result.Ok(n); Try / catch
// Only if you must call ToNumber:
try { var n = words.ToNumber(culture); }
catch (ArgumentException ex) when (ex.Message.StartsWith("Unrecognized number word"))
{ /* handle unknown token */ } Prevention
- Prefer TryToNumber over ToNumber for any untrusted input.
- Match the CultureInfo to the phrase's language.
- Trim and normalize input (collapse spaces, replace typographic quotes) before parsing.
- Inspect the unrecognizedWord out parameter for diagnostics.
When it happens
Trigger: Calling ToNumber(words, culture) (or the converter's Convert) with a phrase whose normalized tokens are not in the locale's linking-affix cardinal map, e.g. a misspelled word, a number from a different locale, or stray punctuation the normalizer does not strip. The throw is produced at line 16 when TryConvert returns false.
Common situations: User-typed free text passed straight into ToNumber; a locale mismatch where English words are parsed under a linking-affix locale (or vice versa); copy-paste with smart quotes or extra tokens; an ordinal/decimal phrase fed to the integer converter.
Related errors
- Input words cannot be empty.
- Unrecognized number word: {unrecognizedWord}
- Unrecognized number word: {unrecognizedWord}
- Unrecognized number word: {unrecognizedWord}
- Unrecognized number word: {unrecognizedWord}
AI-assisted analysis of Humanizr/Humanizer@ffc2b77c0f (2026-08-13).
Data as JSON: /api/errors/0c6565aee778fec9.
Report an issue: GitHub.