Humanizr/Humanizer · error · ArgumentException
Unrecognized number word: {unrecognizedWord}
Error message
Unrecognized number word: {unrecognizedWord} What it means
PrefixedTensScaleWordsToNumberConverter.Convert throws this ArgumentException at line 17 when TryConvert fails, surfacing the first token it could not map under the prefixed-tens-scale grammar. Only the throwing Convert path raises it; the Try overloads return false with the unrecognized token. This converter caps recursion at MaximumParseDepth (128).
Source
Thrown at src/Humanizer/Localisation/WordsToNumber/PrefixedTensScaleWordsToNumberConverter.cs:17
namespace Humanizer;
/// <summary>
/// Parses languages that attach scale words and tens stems as prefixes inside a glued compound.
/// </summary>
internal class PrefixedTensScaleWordsToNumberConverter(PrefixedTensScaleWordsToNumberProfile profile) : GenderlessWordsToNumberConverter
{
const int MaximumParseDepth = 128;
readonly PrefixedTensScaleWordsToNumberProfile 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 = Normalize(words);View on GitHub (pinned to ffc2b77c0f)
Solutions
- Replace ToNumber with TryToNumber(words, out var n, culture, out var bad) and handle false.
- Use the reported bad token to correct the input or pick the right culture.
- Shorten or rephrase very long inputs to stay within the parse-depth limit.
- Confirm the locale matches the phrase's grammar family.
Example fix
// before
var n = phrase.ToNumber(culture);
// after
if (phrase.TryToNumber(out var n, culture, out var bad))
Use(n);
else
Log($"could not parse near '{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.
- Avoid extremely long phrases that may hit the 128-depth parse cap.
- Pre-clean input before parsing.
When it happens
Trigger: Calling ToNumber with a phrase whose tokens are outside the locale's prefixed-tens-scale cardinal map, e.g. foreign words, misspellings, ordinals, or tokens exceeding the 128-depth parse limit. Fires at line 17 when TryConvert returns false.
Common situations: Wrong culture for the phrase's language; user free text; very long or pathological inputs hitting the parse-depth cap; tokens with punctuation the normalizer leaves behind.
Related errors
- Unrecognized number word: {unrecognizedWord}
- Input words cannot be empty.
- 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/57dff85b4f80119b.
Report an issue: GitHub.