Humanizr/Humanizer · error · ArgumentException
Input words cannot be empty.
Error message
Input words cannot be empty.
What it means
LinkingAffixWordsToNumberConverter.TryConvert throws this ArgumentException at line 31 when the input is null, empty, or whitespace. Unlike the 'unrecognized word' throw, this one is inside the Try overload, so even TryToNumber will throw on empty input. The converter cannot normalize or tokenize an empty phrase, so it rejects it up front rather than returning a misleading false.
Source
Thrown at src/Humanizer/Localisation/WordsToNumber/LinkingAffixWordsToNumberConverter.cs:31
{
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 = TokenMapWordsToNumberNormalizer.Normalize(
words.Replace("'", string.Empty).Replace("’", string.Empty),
TokenMapNormalizationProfile.LowercaseReplacePeriodsWithSpaces);
var negative = false;
foreach (var negativePrefix in profile.NegativePrefixes)
{
if (!normalized.StartsWith(negativePrefix, StringComparison.Ordinal))
{
continue;
}
negative = true;
normalized = normalized[negativePrefix.Length..].Trim();
break;
}View on GitHub (pinned to ffc2b77c0f)
Solutions
- Guard the input with !string.IsNullOrWhiteSpace(words) before calling any To/Try number method.
- Treat blank input as a caller-side condition (return early, prompt again) rather than relying on the parser.
- Add null-coalescing/normalization upstream so empty never reaches the converter.
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
// Guard empty/whitespace BEFORE calling (Try* also throws on empty).
if (string.IsNullOrWhiteSpace(words))
return Result.Skip();
return Result.Ok(words.TryToNumber(out var n, culture) ? n : 0); Try / catch
try { var n = words.ToNumber(culture); }
catch (ArgumentException ex) when (ex.Message == "Input words cannot be empty.")
{ /* input was blank */ } Prevention
- Never assume Try* is non-throwing for empty input in Humanizer.
- Centralize a !IsNullOrWhiteSpace guard for all number-word entry points.
- Treat blank as a caller-side condition, not a parse failure.
When it happens
Trigger: Passing null, string.Empty, or a whitespace-only string (" ", tabs) to ToNumber or TryToNumber on a locale backed by the linking-affix converter. The IsNullOrWhiteSpace check at line 29 fires before any tokenization.
Common situations: Unvalidated UI input; reading a field that is blank in the data; trimming a value down to empty and then parsing it; a pipeline step that substitutes empty for missing data.
Related errors
- Unrecognized number word: {unrecognizedWord}
- Input words cannot be empty.
- Input words cannot be empty.
- 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/6cf648d17d762a00.
Report an issue: GitHub.