Humanizr/Humanizer · error · InvalidOperationException

Indian scale-form number profiles require positive scale val

Error message

Indian scale-form number profiles require positive scale values.

What it means

Profile constructor validation: every scale row's Value must be strictly positive (> 0). A non-positive scale value is rejected at instantiation.

Source

Thrown at src/Humanizer/Localisation/NumberToWords/IndianScaleFormNumberToWordsConverter.cs:160

        {
            throw new InvalidOperationException("Indian scale-form number profiles require dense words for 0 through 99.");
        }

        return value;
    }

    static IndianScaleForm[] ValidateScales(IndianScaleForm[] value, int denseUnitCount)
    {
        if (value.Length == 0 || value[^1].Value > denseUnitCount)
        {
            throw new InvalidOperationException("Indian scale-form number profiles require a scale value covered by the dense unit map range.");
        }

        for (var i = 0; i < value.Length; i++)
        {
            if (value[i].Value <= 0)
            {
                throw new InvalidOperationException("Indian scale-form number profiles require positive scale values.");
            }

            if (i > 0 && value[i - 1].Value <= value[i].Value)
            {
                throw new InvalidOperationException("Indian scale-form number profiles require scales in descending order.");
            }
        }

        return value;
    }
}

/// <summary>
/// Describes one scale row with exact and continuing forms.
/// </summary>
/// <param name="Value">The numeric scale value.</param>
/// <param name="Singular">The singular scale form used when the phrase ends at this scale.</param>
/// <param name="SingularWithRemainder">The singular scale form used before a remainder.</param>

View on GitHub (pinned to ffc2b77c0f)

Solutions

  1. Report the locale bug — a scale value is non-positive.
  2. Use a locale with correct scale values.
  3. If authoring, fix the offending scale Value to a positive integer.
Defensive patterns

Strategy: try-catch

Validate before calling

// Construction-time validation; no public pre-check. Isolate converter resolution per culture.

Try / catch

string words;
try
{
    words = value.ToWords(culture);
}
catch (InvalidOperationException ex) when (ex.Message.Contains("positive scale values"))
{
    words = value.ToWords(CultureInfo.InvariantCulture);
}

Prevention

When it happens

Trigger: First converter use for an IndianScaleForm culture whose scale data includes a Value <= 0.

Common situations: Locale YAML typo entering 0 or a negative scale value.

Related errors


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