Humanizr/Humanizer · error · InvalidOperationException

'{path}' must define 'classification'.

Error message

'{path}' must define 'classification'.

What it means

Thrown by ParseLegacyForTests when the durationCases mapping has no 'classification' key at all (GetScalar returns null). Every durationCases block — legacy or explicit — must declare how the locale handles grammatical case for duration units.

Source

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

        }

        static DurationCaseCatalog ParseLegacyForTests(
            string localeCode,
            SimpleYamlMapping mapping,
            string path)
        {
            RejectUnknownKeys(mapping, path, ["classification", "cases"]);

            var classification = mapping.GetScalar("classification") switch
            {
                "distinct" => DurationCaseClassification.Distinct,
                "same-as-nominative" => DurationCaseClassification.Invariant,
                "not-applicable" => DurationCaseClassification.NotApplicable,
                "unsupported" => DurationCaseClassification.Unsupported,
                { } unsupported => throw new InvalidOperationException(
                    $"'{path}.classification' has unsupported value '{unsupported}'. " +
                    "Supported values: distinct, same-as-nominative, not-applicable, unsupported."),
                null => throw new InvalidOperationException($"'{path}' must define 'classification'.")
            };

            if (classification != DurationCaseClassification.Distinct)
            {
                if (mapping.TryGetValue("cases", out _))
                {
                    throw new InvalidOperationException(
                        $"'{path}.cases' is only valid when classification is 'distinct'.");
                }

                return new DurationCaseCatalog(
                    localeCode,
                    classification,
                    "nominative",
                    classification == DurationCaseClassification.Invariant ? ["nominative"] : [],
                    EmptyRealizations(),
                    EmptySources(),
                    classification == DurationCaseClassification.Invariant

View on GitHub (pinned to ffc2b77c0f)

Solutions

  1. Add a 'classification' scalar to the durationCases mapping (e.g. 'classification: distinct').
  2. Verify YAML indentation — the classification key must be a direct child of durationCases, not nested deeper.
  3. Use a known-good locale file as a template to confirm the expected key structure.

Example fix

# before (missing classification)
durationCases:
  cases:
    genitive: { ... }
# after
durationCases:
  classification: distinct
  cases:
    genitive: { ... }
Defensive patterns

Strategy: validation

Validate before calling

// Ensure durationCases has a classification scalar
static bool HasClassification(SimpleYamlMapping durationCases) =>
    durationCases.GetScalar("classification") is not null;

Prevention

When it happens

Trigger: ParseLegacyForTests's switch expression hits the null pattern when mapping.GetScalar('classification') returns null. For example 'durationCases:\n cases:\n genitive: ...' without a classification line.

Common situations: A contributor writes a durationCases block with cases but forgets the classification header. Or the classification line is indented incorrectly so YAML parses it as a child of another key rather than a top-level scalar of durationCases.

Related errors


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