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

  1. Replace ToNumber with TryToNumber(words, out var n, culture, out var bad) and handle false.
  2. Use the reported bad token to correct the input or pick the right culture.
  3. Shorten or rephrase very long inputs to stay within the parse-depth limit.
  4. 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

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


AI-assisted analysis of Humanizr/Humanizer@ffc2b77c0f (2026-08-13). Data as JSON: /api/errors/57dff85b4f80119b. Report an issue: GitHub.