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
- Set each prefixed-scale token's value to an unquoted integer: kilo: 1000.
- Remove any string, boolean, or decimal values from the mapping.
- 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
- Use unquoted integer magnitudes for every prefixed-scale token.
- Avoid placing words as mapping values; they belong as keys.
- Build locally so the generator pinpoints the first bad token.
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
- Billion-word cardinal strategy requires a singular billion w
- Billion-word cardinal strategy requires a plural billion wor
- Property '{propertyName}' must be a string, array, or mappin
- Property '{propertyName}' must be a mapping.
- Expected JSON array or mapping.
AI-assisted analysis of Humanizr/Humanizer@ffc2b77c0f (2026-08-13).
Data as JSON: /api/errors/48cbebd5ffa9e6e4.
Report an issue: GitHub.