Humanizr/Humanizer · error · ArgumentException
Unrecognized number word: {unrecognizedWord}
Error message
Unrecognized number word: {unrecognizedWord} What it means
StemmedScaleWordsToNumberConverter.Convert throws this ArgumentException at line 28 when TryConvert cannot map the phrase under the stemmed-scale grammar. The converter pre-builds token and fallback-scale tables from the profile at construction. Only Convert raises it; the Try overloads return false with the unrecognized token.
Source
Thrown at src/Humanizer/Localisation/WordsToNumber/StemmedScaleWordsToNumberConverter.cs:28
readonly StemmedScaleWordsToNumberProfile profile;
readonly FrozenDictionary<string, long> tokenValues;
readonly TokenizedStemmedScaleWord[] tokenizedValues;
readonly TokenizedStemmedScaleWord[] fallbackScales;
public StemmedScaleWordsToNumberConverter(StemmedScaleWordsToNumberProfile profile)
{
this.profile = profile;
tokenValues = BuildTokenValues(profile);
tokenizedValues = Tokenize(tokenValues);
fallbackScales = Tokenize(BuildFallbackScaleValues(profile));
}
/// <inheritdoc />
public override long Convert(string words)
{
if (!TryConvert(words, out var result, out var unrecognizedWord))
{
throw new ArgumentException($"Unrecognized number word: {unrecognizedWord}");
}
return result;
}
/// <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 source = words.Trim();View on GitHub (pinned to ffc2b77c0f)
Solutions
- Switch to TryToNumber(words, out var n, culture, out var bad) and handle false.
- Use the reported bad token to correct the phrase or the culture.
- Pre-clean input and confirm locale match before parsing.
Example fix
// before
var n = phrase.ToNumber(culture);
// after
if (phrase.TryToNumber(out var n, culture, out var bad))
Use(n);
else
Warn($"unrecognized: {bad}"); Defensive patterns
Strategy: validation
Validate before calling
if (!words.TryToNumber(out var n, culture, out var unrecognized))
return Result.Fail($"unrecognized token: {unrecognized}");
return Result.Ok(n); Try / catch
try { var n = words.ToNumber(culture); }
catch (ArgumentException ex) when (ex.Message.StartsWith("Unrecognized number word"))
{ /* handle */ } Prevention
- Use TryToNumber for untrusted input.
- Match culture to phrase language.
- Pre-clean input before parsing.
- Inspect the unrecognized token.
When it happens
Trigger: Calling ToNumber with tokens not present in the stemmed-scale token map or fallback scales; foreign words, misspellings, or unsupported ordinals. Fires at line 28 when TryConvert returns false.
Common situations: Wrong culture for the phrase; user free text; stemmed/inflected forms the map does not cover; leftover punctuation.
Related errors
- Unrecognized number word: {unrecognizedWord}
- Unrecognized number word: {unrecognizedWord}
- Unrecognized number word: {unrecognizedWord}
- Input words cannot be empty.
- Unrecognized number word: {unrecognizedWord}
AI-assisted analysis of Humanizr/Humanizer@ffc2b77c0f (2026-08-13).
Data as JSON: /api/errors/bf69a8f5f849f6a1.
Report an issue: GitHub.