Humanizr/Humanizer · error · InvalidOperationException

Duration case phrases use unsupported plural rule

Error message

Duration case phrases use unsupported plural rule '{pluralRule}'.

What it means

Thrown by GetRequiredMultipleForms when the plural rule string passed to DurationCaseNormalization.Parse does not match any of the known plural-rule identifiers. The switch expression has a default arm that throws for any unrecognized value, because the generator needs the plural rule to compute which multiple forms each phrase must define.

Solutions

  1. Check the locale's declared plural rule and compare it against the accepted values in GetRequiredMultipleForms: none, singular-plural, arabic-like, arabic-cardinal, between2-and4-paucal, polish, south-slavic, russian, slovenian, lithuanian.
  2. Correct the plural rule to match one of the supported identifiers (or pass null/omit it for languages with no plural distinction).
  3. If a genuinely new plural rule is needed, add a case to the switch in GetRequiredMultipleForms and specify the required forms array.

Example fix

# before
pluralRule: one-many
# after
pluralRule: singular-plural
Defensive patterns

Strategy: validation

Validate before calling

# Check plural rule against the supported set before building
$supported = @('none','singular-plural','arabic-like','arabic-cardinal','between2-and4-paucal','polish','south-slavic','russian','slovenian','lithuanian')
# Read the locale's declared pluralRule and verify membership

Prevention

When it happens

Trigger: The locale YAML (or caller) supplies a pluralRule value that is not one of: null, 'none', 'singular-plural', 'arabic-like', 'arabic-cardinal', 'between2-and4-paucal', 'polish', 'south-slavic', 'russian', 'slovenian', or 'lithuanian'.

Common situations: A contributor introduces a new plural-rule family or renames an existing one in the locale metadata without updating the generator's switch table. Also occurs if a locale's plural rule is misspelled or uses a different casing/convention than expected.

Related errors


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

Appendix: source

Thrown at src/Humanizer.SourceGenerators/Common/DurationCaseModels.cs:842

                null,
                null,
                RequireReason(mapping.GetScalar("unsupported")!, $"{path}.unsupported"),
                ParseProvenance(mapping, path, required: false));
        }

        static ImmutableArray<string> GetRequiredMultipleForms(string? pluralRule) =>
            pluralRule switch
            {
                null or "none" => [],
                "singular-plural" => ["default", "plural"],
                "arabic-like" => ["default", "dual", "plural"],
                "arabic-cardinal" => ["default", "zero", "dual", "plural", "many"],
                "between2-and4-paucal" or "polish" => ["default", "paucal"],
                "south-slavic" or "russian" =>
                    ["default", "singular", "paucal"],
                "slovenian" => ["default", "dual", "paucal"],
                "lithuanian" => ["default", "singular", "plural"],
                _ => throw new InvalidOperationException(
                    $"Duration case phrases use unsupported plural rule '{pluralRule}'.")
            };

        static void ValidateReachableMultipleForms(
            SimpleYamlValue phraseValue,
            string path,
            ImmutableArray<string> requiredMultipleForms)
        {
            var phrase = ExpectMapping(phraseValue, path);
            if (!phrase.TryGetValue("multiple", out var multipleValue))
            {
                throw new InvalidOperationException(
                    $"Case overlay '{path}' must explicitly define numeric multiple forms.");
            }

            if (requiredMultipleForms.IsEmpty)
            {
                return;

View on GitHub (pinned to ffc2b77c0f)