Humanizr/Humanizer · error · InvalidOperationException
Inflection defines unsupported quantity selector; expected '
Error message
Inflection defines unsupported quantity selector; expected 'exact-numeric-singleton'.
What it means
The inflection surface accepts an optional 'quantitySelector' key, but the only supported value is the literal string 'exact-numeric-singleton'. ParseQuantitySelector throws when the key is present with any other value. The throw is caught during catalog collection and surfaced as an HSG003 diagnostic, which suppresses that locale's generated inflection catalog.
Source
Thrown at src/Humanizer.SourceGenerators/Generators/ProfileCatalogs/InflectionCatalogParsing.cs:162
NormalizeGuards(
GetOptionalStrings(mapping, "skipSimpleWords", "skip-simple-words"),
casing,
scripts,
"skipSimpleWords"),
lexemes,
rules));
}
static string? ParseQuantitySelector(SimpleYamlMapping mapping)
{
if (!mapping.TryGetValue("quantitySelector", out var value))
{
return null;
}
return value is SimpleYamlScalar { Value: ExactNumericSingletonSelector }
? ExactNumericSingletonSelector
: throw new InvalidOperationException(
"Inflection defines unsupported quantity selector; expected 'exact-numeric-singleton'.");
}
static void ValidateQuantitySelector(
SimpleYamlMapping mapping,
string cardinalRule,
string? quantitySelector,
ImmutableArray<InflectionLexemeInput> lexemes,
ImmutableArray<InflectionRuleInput> rules)
{
var hasOptedLexeme = lexemes.Any(static lexeme =>
lexeme.Display.ContainsKey("one"));
if (quantitySelector is not null)
{
if (!hasOptedLexeme)
{
throw new InvalidOperationException(
"Inflection quantitySelector 'exact-numeric-singleton' requires at least one lexeme with an authored 'one' display.");View on GitHub (pinned to ffc2b77c0f)
Solutions
- Set the value to exactly 'exact-numeric-singleton'
- Remove the quantitySelector key entirely if the locale does not need singleton-one selection
Example fix
# before
quantitySelector: 'nearest-numeric-singleton'
# after
quantitySelector: 'exact-numeric-singleton' Defensive patterns
Strategy: validation
Validate before calling
// In a locale-YAML lint pass, before building:
// 1. Parse surfaces.inflection into a SimpleYamlMapping `m`.
// 2. If m contains 'quantitySelector', its scalar must be exactly:
if (m.TryGetValue("quantitySelector", out var v) &&
(v is not SimpleYamlScalar s || s.Value != "exact-numeric-singleton"))
{
Report($"{locale}: quantitySelector must be 'exact-numeric-singleton' or absent.");
} Type guard
static bool IsValidQuantitySelector(SimpleYamlMapping m) =>
!m.TryGetValue("quantitySelector", out var v) ||
v is SimpleYamlScalar { Value: "exact-numeric-singleton" }; Prevention
- Keep quantitySelector absent unless you specifically need singular-quantity selection
- Copy from ExactNumericSingletonInflectionFixture when enabling it
- Run 'dotnet build' after every locale edit; HSG003 points at the offending locale
When it happens
Trigger: A locale YAML sets 'quantitySelector:' under 'surfaces.inflection' to anything other than 'exact-numeric-singleton' (e.g. 'nearest-numeric-singleton', a typo, or a scalar with different casing).
Common situations: Authoring a new locale that needs per-number singular/plural behavior and guessing the selector name; copy-paste from an unrelated spec; renaming the key during a refactor without checking the parser's single accepted constant.
Related errors
- Inflection quantitySelector 'exact-numeric-singleton' requir
- Inflection quantitySelector 'exact-numeric-singleton' cannot
- Inflection display category 'one' is unreachable without qua
- Active inflection bundle must define lexemes.
- Inflection lexemes must be mappings.
AI-assisted analysis of Humanizr/Humanizer@ffc2b77c0f (2026-08-13).
Data as JSON: /api/errors/86f8953e7eb61729.
Report an issue: GitHub.