{"record":{"id":"7a23b91cd74eba25","repo":"Humanizr/Humanizer","slug":"path-must-define-scalar-key","errorCode":null,"errorMessage":"'{path}' must define scalar '{key}'.","messagePattern":"'(.+?)' must define scalar '(.+?)'\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Humanizer.SourceGenerators/Common/DurationCaseModels.cs","lineNumber":1093,"sourceCode":"\n            return result.MoveToImmutable();\n        }\n\n        static void ValidateProvenance(\n            ImmutableArray<string> provenance,\n            ImmutableDictionary<string, DurationCaseSource> sources,\n            string path)\n        {\n            foreach (var sourceId in provenance.Where(sourceId => !sources.ContainsKey(sourceId)))\n            {\n                throw new InvalidOperationException(\n                    $\"'{path}.provenance' references unknown source '{sourceId}'.\");\n            }\n        }\n\n        static string RequireScalar(SimpleYamlMapping mapping, string key, string path) =>\n            mapping.GetScalar(key)\n            ?? throw new InvalidOperationException($\"'{path}' must define scalar '{key}'.\");\n\n        static string RequireReason(string reason, string path) =>\n            string.IsNullOrWhiteSpace(reason)\n                ? throw new InvalidOperationException($\"'{path}' must not be empty.\")\n                : reason;\n\n        static ImmutableDictionary<string, DurationCaseRealization> EmptyRealizations() =>\n            ImmutableDictionary<string, DurationCaseRealization>.Empty.WithComparers(StringComparer.Ordinal);\n\n        static DurationCaseOverlay CreateBaseDurationOverlay()\n        {\n            var units = ImmutableDictionary.CreateBuilder<string, DurationCaseUnit>(StringComparer.Ordinal);\n            foreach (var unit in TimeUnits)\n            {\n                units[unit] = new DurationCaseUnit(DurationCaseUnitKind.SameAsNominative, null);\n            }\n\n            return new DurationCaseOverlay(units.ToImmutable());","sourceCodeStart":1075,"sourceCodeEnd":1111,"githubUrl":"https://github.com/Humanizr/Humanizer/blob/ffc2b77c0f30d2fb176875841424379319d0ae9b/src/Humanizer.SourceGenerators/Common/DurationCaseModels.cs#L1075-L1111","documentation":"Thrown by RequireScalar when a mapping does not contain the requested scalar key (GetScalar returns null). This helper is used to fetch mandatory scalar values such as sameRenderedAs targets, notApplicable reasons, or unsupported reasons within various mapping contexts.","triggerScenarios":"A code path calls RequireScalar for a key that is absent from the mapping. In the duration-case model, this surfaces when an expected scalar value is missing from a realization or source mapping.","commonSituations":"A contributor uses a discriminator key that the parser accepts as present but then the downstream RequireScalar call for a companion field finds nothing. Also occurs when editing source objects that omit a mandatory scalar field (kind, url, revision, locator, credit).","solutions":["Inspect the mapping at the reported path and identify the missing scalar key named in the message.","Add the scalar value (a non-null YAML string) for that key.","Rebuild to confirm the scalar is found."],"exampleFix":"# before — source object missing 'revision'\ncldr-42:\n  kind: cldr\n  url: https://unicode.org/cldr\n  locator: common/...\n  credit: Unicode\n# after\ncldr-42:\n  kind: cldr\n  url: https://unicode.org/cldr\n  revision: '42'\n  locator: common/...\n  credit: Unicode","handlingStrategy":"validation","validationCode":"# Verify mandatory scalar fields exist in source objects and realizations\n# python: required_fields = ['kind','url','revision','locator','credit']\n#         for sid, src in yaml['durationCases']['sources'].items():\n#             for f in required_fields: assert f in src, f'missing {f} in source {sid}'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use a source-entry template with all mandatory fields (kind, url, revision, locator, credit) pre-filled.","Validate source objects with a YAML schema before building.","Build after adding each source to catch missing-scalar errors at the specific path."],"tags":["humanizer","locale","yaml","source-generator","duration-cases","scalar","build-time"],"backgroundTag":null,"analyzedSha":"ffc2b77c0f30d2fb176875841424379319d0ae9b","analyzedAt":"2026-08-13T21:42:34.584Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}