Humanizr/Humanizer · error · ArgumentException

Value cannot be empty or whitespace.

Error message

Value cannot be empty or whitespace.

What it means

Thrown by the PluralizationForms constructor when the 'singular' or 'other' argument is empty or whitespace-only. These two forms are mandatory for every pluralization entry because the CLDR plural rules always resolve to at least one of them. An empty required form would produce broken output.

Source

Thrown at src/Humanizer/PluralizationForms.cs:173

        {
            CardinalPluralCategory.Other => Other,
            CardinalPluralCategory.Zero => Zero,
            CardinalPluralCategory.One => One,
            CardinalPluralCategory.Two => Two,
            CardinalPluralCategory.Few => Few,
            CardinalPluralCategory.Many => Many,
            _ => throw new ArgumentOutOfRangeException(nameof(category))
        };

        return form is not null;
    }

    static string RequireForm(string value, string parameterName)
    {
        ArgumentNullException.ThrowIfNull(value, parameterName);
        if (string.IsNullOrWhiteSpace(value))
        {
            throw new ArgumentException("Value cannot be empty or whitespace.", parameterName);
        }

        return value;
    }

    static string? ValidateOptionalForm(string? value, string parameterName)
    {
        if (value is not null && string.IsNullOrWhiteSpace(value))
        {
            throw new ArgumentException("Value cannot be empty or whitespace.", parameterName);
        }

        return value;
    }

    static bool Matches(string normalized, string? candidate) =>
        candidate is not null &&
        string.Equals(normalized, Normalize(candidate), StringComparison.Ordinal);

View on GitHub (pinned to ffc2b77c0f)

Solutions

  1. Validate that singular and other are non-blank before constructing PluralizationForms.
  2. Check your locale data source for empty or whitespace-only required fields.
  3. Provide sensible defaults (e.g. the singular form as 'other') when data is missing.

Example fix

// before
var forms = new PluralizationForms(singular, other);

// after
if (string.IsNullOrWhiteSpace(singular) || string.IsNullOrWhiteSpace(other))
    throw new InvalidOperationException("Pluralization data is incomplete.");
var forms = new PluralizationForms(singular, other);
Defensive patterns

Strategy: validation

Validate before calling

static void ValidateRequiredForms(string singular, string other)
{
    if (string.IsNullOrWhiteSpace(singular))
        throw new InvalidOperationException("singular is required");
    if (string.IsNullOrWhiteSpace(other))
        throw new InvalidOperationException("other is required");
}

Prevention

When it happens

Trigger: Constructing new PluralizationForms("", "words") or new PluralizationForms("word", " "). The RequireForm helper is called on the first two positional parameters.

Common situations: Loading pluralization data from a YAML/JSON file where a required field is blank. Building PluralizationForms dynamically from user input without trimming/validation. Migrating locale data with a missing 'other' key.

Related errors


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