Humanizr/Humanizer · error · InvalidOperationException

Scale-leading compound parser profiles require positive scal

Error message

Scale-leading compound parser profiles require positive scale values.

What it means

ScaleLeadingCompoundWordsToNumberProfile.ValidateScales throws this InvalidOperationException at line 436 when any scale value is zero or negative. The grammar multiplies counts by scale values, so non-positive scales are meaningless and rejected eagerly at profile construction. This is a locale-authoring/config defect surfaced during registry initialization.

Source

Thrown at src/Humanizer/Localisation/WordsToNumber/ScaleLeadingCompoundWordsToNumberConverter.cs:436

        var maximum = 1;
        foreach (var value in values)
        {
            maximum = Math.Max(maximum, Tokenize(value).Length);
        }

        return maximum;
    }

    static string[] Tokenize(string value) =>
        value.Split(' ', StringSplitOptions.RemoveEmptyEntries);

    static ScaleLeadingCompoundScale[] ValidateScales(ScaleLeadingCompoundScale[] value)
    {
        for (var i = 0; i < value.Length; i++)
        {
            if (value[i].Value <= 0)
            {
                throw new InvalidOperationException("Scale-leading compound parser profiles require positive scale values.");
            }

            if (i > 0)
            {
                var previous = (ulong)value[i - 1].Value;
                var current = (ulong)value[i].Value;
                if (previous <= current || previous % current != 0)
                {
                    throw new InvalidOperationException("Scale-leading compound parser profiles require descending scales where each larger scale is divisible by the next smaller scale.");
                }
            }
        }

        return value;
    }
}

View on GitHub (pinned to ffc2b77c0f)

Solutions

  1. Ensure every scale value in the locale's scale ladder is a positive integer.
  2. Regenerate locale source and run the locale tests.
  3. Add an authoring test that constructs the profile and asserts no throw.

Example fix

// before (profile scales)
Scales: [ 1000000, 0, 100 ]   // 0 <= 0 -> throws
// after
Scales: [ 1000000, 1000, 100 ]
Defensive patterns

Strategy: validation

Validate before calling

// Authoring guard: no scale value may be <= 0.
static bool ScalesPositive(long[] scales) => scales.All(s => s > 0);

Prevention

When it happens

Trigger: A locale scale ladder containing a 0 or negative value (typo, missing value, sign error in YAML). The throw occurs when the profile is constructed by the generator/registry, typically at first use of the culture.

Common situations: Adding a scale-leading locale with an incomplete scale entry; YAML parsing a missing number as 0; copy-paste leaving a placeholder; generator wiring bug.

Related errors


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