Humanizr/Humanizer · error · ArgumentException
Input words cannot be empty.
Error message
Input words cannot be empty.
What it means
PrefixedTensScaleWordsToNumberConverter.TryConvert throws this ArgumentException at line 32 for null, empty, or whitespace input. Because it lives in the Try overload, both ToNumber and TryToNumber throw on empty input; the parser cannot tokenize an empty phrase.
Source
Thrown at src/Humanizer/Localisation/WordsToNumber/PrefixedTensScaleWordsToNumberConverter.cs:32
{
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);
var negative = false;
foreach (var prefix in profile.NegativePrefixes)
{
if (!normalized.StartsWith(prefix, StringComparison.Ordinal))
{
continue;
}
negative = true;
normalized = normalized[prefix.Length..];
break;
}
normalized = CollapseCompoundSeparators(normalized);View on GitHub (pinned to ffc2b77c0f)
Solutions
- Pre-check !string.IsNullOrWhiteSpace(words) before calling any number method.
- Handle blank as a caller-side condition (skip, reprompt) rather than letting the parser reject it.
- Normalize upstream so empty never reaches the converter.
Example fix
// before var ok = "".TryToNumber(out var n, culture); // after var ok = !string.IsNullOrWhiteSpace(input) && input.TryToNumber(out var n, culture);
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
- Always guard IsNullOrWhiteSpace before number-word calls.
- Treat blank input as a caller condition.
- Centralize empty-input handling.
When it happens
Trigger: Passing null, string.Empty, or whitespace-only strings to ToNumber or TryToNumber on a locale using the prefixed-tens-scale converter. The IsNullOrWhiteSpace check at line 31 fires before normalization.
Common situations: Blank form fields, trimmed-to-empty values, missing data substituted with empty, unvalidated external input.
Related errors
- Input words cannot be empty.
- Unrecognized number word: {unrecognizedWord}
- 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/10c04eff32f1749e.
Report an issue: GitHub.