{"record":{"id":"cbd38e630cbf1386","repo":"Humanizr/Humanizer","slug":"path-cases-is-only-valid-when-classification-i","errorCode":null,"errorMessage":"'{path}.cases' is only valid when classification is 'distinct'.","messagePattern":"'(.+?)\\.cases' is only valid when classification is 'distinct'\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Humanizer.SourceGenerators/Common/DurationCaseModels.cs","lineNumber":339,"sourceCode":"            RejectUnknownKeys(mapping, path, [\"classification\", \"cases\"]);\n\n            var classification = mapping.GetScalar(\"classification\") switch\n            {\n                \"distinct\" => DurationCaseClassification.Distinct,\n                \"same-as-nominative\" => DurationCaseClassification.Invariant,\n                \"not-applicable\" => DurationCaseClassification.NotApplicable,\n                \"unsupported\" => DurationCaseClassification.Unsupported,\n                { } unsupported => throw new InvalidOperationException(\n                    $\"'{path}.classification' has unsupported value '{unsupported}'. \" +\n                    \"Supported values: distinct, same-as-nominative, not-applicable, unsupported.\"),\n                null => throw new InvalidOperationException($\"'{path}' must define 'classification'.\")\n            };\n\n            if (classification != DurationCaseClassification.Distinct)\n            {\n                if (mapping.TryGetValue(\"cases\", out _))\n                {\n                    throw new InvalidOperationException(\n                        $\"'{path}.cases' is only valid when classification is 'distinct'.\");\n                }\n\n                return new DurationCaseCatalog(\n                    localeCode,\n                    classification,\n                    \"nominative\",\n                    classification == DurationCaseClassification.Invariant ? [\"nominative\"] : [],\n                    EmptyRealizations(),\n                    EmptySources(),\n                    classification == DurationCaseClassification.Invariant\n                        ? ImmutableDictionary<string, DurationCaseOverlay>.Empty\n                            .WithComparers(StringComparer.Ordinal)\n                            .Add(\"nominative\", CreateBaseDurationOverlay())\n                        : ImmutableDictionary<string, DurationCaseOverlay>.Empty.WithComparers(StringComparer.Ordinal));\n            }\n\n            if (!mapping.TryGetValue(\"cases\", out var casesValue))","sourceCodeStart":321,"sourceCodeEnd":357,"githubUrl":"https://github.com/Humanizr/Humanizer/blob/ffc2b77c0f30d2fb176875841424379319d0ae9b/src/Humanizer.SourceGenerators/Common/DurationCaseModels.cs#L321-L357","documentation":"Thrown by ParseLegacyForTests when the durationCases block includes a 'cases' key but the classification is not 'distinct'. Cases (genitive, dative, etc.) only make sense when the locale actually has distinct case forms. For 'same-as-nominative', 'not-applicable', and 'unsupported', no cases block should be present.","triggerScenarios":"After resolving classification, ParseLegacyForTests checks if classification != Distinct and mapping has 'cases'. If so, it throws. For example 'classification: same-as-nominative\\ncases:\\n  genitive: ...' triggers it.","commonSituations":"A contributor changes classification from 'distinct' to 'same-as-nominative' but leaves the cases block in place. Or a copy-paste from a distinct locale includes cases that are no longer relevant after reclassification.","solutions":["Remove the 'cases' key and its children if the classification is not 'distinct'.","If cases are genuinely needed, change classification back to 'distinct'.","Review the locale's grammar to confirm whether case distinctions actually apply before choosing classification."],"exampleFix":"# before (cases without distinct classification)\ndurationCases:\n  classification: same-as-nominative\n  cases:\n    genitive: { ... }\n# after (remove cases for non-distinct)\ndurationCases:\n  classification: same-as-nominative","handlingStrategy":"validation","validationCode":"// Cases only valid when classification is distinct\nstatic bool CasesConsistentWithClassification(SimpleYamlMapping durationCases)\n{\n    var classification = durationCases.GetScalar(\"classification\");\n    var hasCases = durationCases.TryGetValue(\"cases\", out _);\n    return classification != \"distinct\" ? !hasCases : true;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Remove the 'cases' block when classification is not 'distinct'.","When reclassifying, clean up keys that are no longer valid.","Review the full durationCases block after any classification change."],"tags":["source-generator","duration-cases","legacy-format","testing","classification"],"backgroundTag":null,"analyzedSha":"ffc2b77c0f30d2fb176875841424379319d0ae9b","analyzedAt":"2026-08-13T21:42:34.584Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}