Humanizr/Humanizer · error · ArgumentException
Input words cannot be empty.
Error message
Input words cannot be empty.
What it means
TokenMapWordsToNumberConverter.TryConvert throws this ArgumentException at line 46 for null, empty, or whitespace input. Because it is inside the Try overload, both ToNumber and TryToNumber throw on empty phrases; the invariant-integer fast path runs only after this guard.
Source
Thrown at src/Humanizer/Localisation/WordsToNumber/TokenMapWordsToNumberConverter.cs:46
{
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 (rules.AllowInvariantIntegerInput &&
long.TryParse(words.Trim(), NumberStyles.Integer, CultureInfo.InvariantCulture, out parsedValue))
{
unrecognizedWord = null;
return true;
}
var normalizedSource = words.Trim();
var negative = false;
foreach (var negativePrefix in rules.NegativePrefixes)
{
if (!normalizedSource.StartsWith(negativePrefix, StringComparison.Ordinal))
{
continue;
}View on GitHub (pinned to ffc2b77c0f)
Solutions
- Guard with !string.IsNullOrWhiteSpace(words) before any number call.
- Handle blank as a caller-side condition.
- Normalize upstream so empty never reaches the converter.
Example fix
// before
"".TryToNumber(out var n, CultureInfo.GetCultureInfo("en"));
// 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 (this fires for the English fallback too).
- Treat blank input as a caller condition.
- Centralize empty-input handling.
When it happens
Trigger: Passing null, string.Empty, or whitespace to any number method on a token-map locale (including the default English fallback). The IsNullOrWhiteSpace check at line 45 fires first.
Common situations: Blank UI fields, trimmed-to-empty values, unvalidated external input, empty substitution for missing data; hitting this via the English fallback when the requested locale is unsupported and the input was empty.
Related errors
- Input words cannot be empty.
- Input words cannot be empty.
- Input words cannot be empty.
- Input words cannot be empty.
- Unrecognized number word: {unrecognizedWord}
AI-assisted analysis of Humanizr/Humanizer@ffc2b77c0f (2026-08-13).
Data as JSON: /api/errors/e7a14dd8e4e85b27.
Report an issue: GitHub.