Humanizr/Humanizer · error · InvalidOperationException

Prefixed scale token '{property.Name}' must map to an intege

Error message

Prefixed scale token '{property.Name}' must map to an integer value.

What it means

Thrown while building a PrefixedScaleWord[] when the YAML node is a mapping but one of its values is not an integer. The builder maps each prefix token to an integer value; a non-numeric value cannot become the scale's numeric component.

Source

Thrown at src/Humanizer.SourceGenerators/Common/GenerationHelpers.cs:1331

            RequiredInt64Value("value"));

    static string CreatePrefixedScaleWordArrayExpression(JsonElement arrayElement)
    {
        if (arrayElement.ValueKind is not (JsonValueKind.Array or JsonValueKind.Object))
        {
            throw new InvalidOperationException("Expected JSON array or mapping.");
        }

        var builder = new StringBuilder("new PrefixedScaleWord[] { ");
        var first = true;

        if (arrayElement.ValueKind == JsonValueKind.Object)
        {
            foreach (var (Name, Value) in arrayElement.EnumerateObject()
                         .Select(static property =>
                         {
                             return property.Value.ValueKind != JsonValueKind.Number || !property.Value.TryGetInt64(out var value)
                                 ? throw new InvalidOperationException($"Prefixed scale token '{property.Name}' must map to an integer value.")
                                 : (property.Name, Value: value);
                         })
                         .OrderByDescending(static entry => entry.Value)
                         .ThenBy(static entry => entry.Name, StringComparer.Ordinal))
            {
                if (!first)
                {
                    builder.Append(", ");
                }

                builder.Append("new(");
                builder.Append(QuoteLiteral(Name));
                builder.Append(", ");
                builder.Append(Value.ToString(CultureInfo.InvariantCulture));
                builder.Append(')');
                first = false;
            }
        }

View on GitHub (pinned to ffc2b77c0f)

Solutions

  1. Set each prefixed-scale token's value to an unquoted integer: kilo: 1000.
  2. Remove any string, boolean, or decimal values from the mapping.
  3. Rebuild; the generator names the first remaining offending token.

Example fix

# before
prefixedScale:
  kilo: 'thousand'
# after
prefixedScale:
  kilo: 1000
Defensive patterns

Strategy: validation

Validate before calling

# Every prefixed-scale token must map to an unquoted integer:
#   rg -A10 "prefixedScale" src/Humanizer/Locales/<code>.yml
# No value should be a quoted string or boolean.

Prevention

When it happens

Trigger: A locale YAML defines the prefixed-scale section as a mapping where at least one entry's value is a string, boolean, or non-integer number. The Select lambda checks ValueKind and TryGetInt64 and throws, naming the offending token.

Common situations: A contributor adds a prefix token but supplies a word as the value instead of the integer magnitude. The build error names the specific token that is wrong.

Related errors


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