Humanizr/Humanizer · error · InvalidOperationException

Inflection quantitySelector 'exact-numeric-singleton' cannot

Error message

Inflection quantitySelector 'exact-numeric-singleton' cannot select productive rule display.

What it means

The 'exact-numeric-singleton' selector may only select a lexeme's authored 'one' display. Productive (stem-template) rules must not define a 'one' output, because the singleton path bypasses rule application for quantity 1. ValidateQuantitySelector throws when any rule has a 'display.one' entry while the selector is active.

Source

Thrown at src/Humanizer.SourceGenerators/Generators/ProfileCatalogs/InflectionCatalogParsing.cs:185

            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.");
                }

                if (rules.Any(static rule => rule.Display.ContainsKey("one")))
                {
                    throw new InvalidOperationException(
                        "Inflection quantitySelector 'exact-numeric-singleton' cannot select productive rule display.");
                }

                return;
            }

            if (!IsCategoryReachable(mapping, cardinalRule, "one") &&
                (hasOptedLexeme ||
                 rules.Any(static rule => rule.Display.ContainsKey("one"))))
            {
                throw new InvalidOperationException(
                    "Inflection display category 'one' is unreachable without quantitySelector 'exact-numeric-singleton'.");
            }
        }

        static bool IsCategoryReachable(
            SimpleYamlMapping mapping,
            string cardinalRule,

View on GitHub (pinned to ffc2b77c0f)

Solutions

  1. Remove the 'one:' key from each rule's 'output.display', keeping only categories the rule should produce (typically 'other')
  2. Drop the quantitySelector and let productive rules produce 'one' instead

Example fix

# before (rule output)
        output:
          dictionary-plural: '{stem}ies'
          display:
            one: '{stem}y'
            other: '{stem}ies'
# after
        output:
          dictionary-plural: '{stem}ies'
          display:
            other: '{stem}ies'
Defensive patterns

Strategy: validation

Validate before calling

// Reject rule display.one while the singleton selector is active:
if (selectorSet && rules.Any(r => r.Output.Display.ContainsKey("one")))
    Report($"{locale}: rules must not define display.one with the singleton selector.");

Type guard

static bool RulesHaveNoProductiveOne(bool selectorSet, IEnumerable<Rule> rules) =>
    !selectorSet || rules.All(r => !r.Display.ContainsKey("one"));

Prevention

When it happens

Trigger: quantitySelector is set AND a rule under 'rules:' defines 'output.display.one' as a stem template (e.g. 'one: {stem}y').

Common situations: Copying the ProductiveInflectionFixture (which authors both 'one' and 'other' rule outputs) and enabling the selector without dropping the rule's 'one' output.

Related errors


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