Humanizr/Humanizer · error · ArgumentException

Input words cannot be empty.

Error message

Input words cannot be empty.

What it means

SuffixScaleWordsToNumberConverter.TryConvert throws this ArgumentException at line 34 for null, empty, or whitespace input. It sits in the Try overload, so both ToNumber and TryToNumber throw on empty phrases; the fast-path long.TryParse runs only after this guard.

Source

Thrown at src/Humanizer/Localisation/WordsToNumber/SuffixScaleWordsToNumberConverter.cs:34

    {
        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.");
        }

        if (long.TryParse(words.Trim(), NumberStyles.Integer, CultureInfo.InvariantCulture, out parsedValue))
        {
            unrecognizedWord = null;
            return true;
        }

        var normalized = Normalize(words);
        var negative = false;

        foreach (var prefix in profile.NegativePrefixes)
        {
            if (!normalized.StartsWith(prefix, StringComparison.Ordinal))
            {
                continue;
            }

View on GitHub (pinned to ffc2b77c0f)

Solutions

  1. Pre-check !string.IsNullOrWhiteSpace(words) before calling.
  2. Handle blank upstream (skip or reprompt).
  3. Ensure empty never reaches the converter via upstream normalization.

Example fix

// before
"   ".TryToNumber(out var n, culture);
// after
if (!string.IsNullOrWhiteSpace(input) && input.TryToNumber(out var n, culture))
    Use(n);
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrWhiteSpace(words))
    return Result.Skip();
var ok = words.TryToNumber(out var n, culture);

Try / catch

try { var n = words.ToNumber(culture); }
catch (ArgumentException ex) when (ex.Message == "Input words cannot be empty.")
    { /* blank input */ }

Prevention

When it happens

Trigger: Passing null, string.Empty, or whitespace to any number method on a suffix-scale locale. The IsNullOrWhiteSpace check at line 33 fires before the invariant-integer fast path.

Common situations: Blank fields, trimmed-to-empty values, unvalidated input, empty substitution for missing data.

Related errors


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