Humanizr/Humanizer · error · InvalidOperationException

Inflection rule '{id}' has unsupported direction '{direction

Error message

Inflection rule '{id}' has unsupported direction '{direction}'.

What it means

A rule's 'direction' must be either 'forward' (singular to plural) or 'reverse' (plural to singular). ParseRules throws for any other value.

Source

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

                    throw new InvalidOperationException("Inflection rules must be mappings.");
                }

                ValidateProperties(
                    rule,
                    "Inflection rule",
                    "id", "direction", "priority", "scope", "match", "output",
                    "hostileExclusions", "hostile-exclusions", "reverse", "sources");
                var id = GetRequiredScalar(rule, "id", "Inflection rule must define id");
                if (!ids.Add(id))
                {
                    throw new InvalidOperationException($"Duplicate inflection rule id '{id}'.");
                }

                ValidateSources(rule, sourceIds, $"Inflection rule '{id}'");
                var direction = GetRequiredScalar(rule, "direction", $"Inflection rule '{id}' must define direction");
                if (direction is not ("forward" or "reverse"))
                {
                    throw new InvalidOperationException($"Inflection rule '{id}' has unsupported direction '{direction}'.");
                }

                var priority = GetRequiredInt(rule, "priority", $"Inflection rule '{id}' must define priority");
                var scope = GetRequiredMapping(rule, "scope", $"Inflection rule '{id}' must define scope");
                ValidateProperties(
                    scope,
                    $"Inflection rule '{id}' scope",
                    "pos", "countability", "token", "scripts");
                if (GetRequiredScalar(scope, "pos", $"Inflection rule '{id}' scope must define pos") != "noun" ||
                    GetRequiredScalar(scope, "token", $"Inflection rule '{id}' scope must define token") != "standalone")
                {
                    throw new InvalidOperationException(
                        $"Inflection rule '{id}' scope must target standalone nouns.");
                }

                var countabilities = GetRequiredStrings(
                    scope,
                    "countability",

View on GitHub (pinned to ffc2b77c0f)

Solutions

  1. Set 'direction: 'forward'' or 'direction: 'reverse''
  2. Split a bidirectional behavior into two rules, one forward and one reverse

Example fix

# before
        direction: 'forwards'
# after
        direction: 'forward'
Defensive patterns

Strategy: validation

Validate before calling

foreach (var rule in rules)
    if (rule.Direction is not "forward" and not "reverse")
        Report($"{locale}: rule '{rule.Id}' direction must be 'forward' or 'reverse'.");

Type guard

static bool DirectionValid(string d) => d is "forward" or "reverse";

Prevention

When it happens

Trigger: 'direction:' is anything other than 'forward' or 'reverse' (e.g. 'forwards', 'bidirectional', a typo).

Common situations: Typo; trying to express a bidirectional rule with one value instead of splitting into separate forward/reverse rules.

Related errors


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