Humanizr/Humanizer · error · ArgumentException
Input words cannot be empty.
Error message
Input words cannot be empty.
What it means
StemmedScaleWordsToNumberConverter.TryConvert throws this ArgumentException at line 43 for null, empty, or whitespace input. Living in the Try overload, it makes both ToNumber and TryToNumber throw on empty phrases; the converter needs at least one token to begin.
Source
Thrown at src/Humanizer/Localisation/WordsToNumber/StemmedScaleWordsToNumberConverter.cs:43
{
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();
var negative = false;
foreach (var prefix in profile.NegativePrefixes)
{
if (!source.StartsWith(prefix, StringComparison.Ordinal))
{
continue;
}
negative = true;
source = source[prefix.Length..].Trim();
break;
}
if (TryParseOrdinal(source, out var ordinalValue))
{View on GitHub (pinned to ffc2b77c0f)
Solutions
- Guard with !string.IsNullOrWhiteSpace(words) before calling.
- Treat blank as a caller-side condition, not a parser error.
- Normalize upstream so empty never reaches the converter.
Example fix
// before
input.TryToNumber(out var n, culture); // throws if input is ""
// 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
- Guard IsNullOrWhiteSpace before number-word calls.
- Treat blank input as a caller condition.
- Normalize upstream so empty never reaches the converter.
When it happens
Trigger: Passing null, string.Empty, or whitespace to any number method on a stemmed-scale locale. The IsNullOrWhiteSpace check at line 42 fires first.
Common situations: Blank inputs, trimmed-to-empty values, unvalidated external data, empty substitution for missing values.
Related errors
- Input words cannot be empty.
- Input words cannot be empty.
- Unrecognized number word: {unrecognizedWord}
- Input words cannot be empty.
- Input words cannot be empty.
AI-assisted analysis of Humanizr/Humanizer@ffc2b77c0f (2026-08-13).
Data as JSON: /api/errors/cccc5653951237c6.
Report an issue: GitHub.