{"record":{"id":"64ab0f7d9ee48fa9","repo":"Humanizr/Humanizer","slug":"missing-required-property-sourcepath","errorCode":null,"errorMessage":"Missing required property '{sourcePath}'.","messagePattern":"Missing required property '(.+?)'\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Humanizer.SourceGenerators/Common/EngineContractUtilities.cs","lineNumber":12,"sourceCode":"using System.Text.Json;\n\nnamespace Humanizer.SourceGenerators;\n\npublic sealed partial class HumanizerSourceGenerator\n{\n    static class EngineContractUtilities\n    {\n        public static JsonElement GetRequiredElement(JsonElement root, string? sourcePath) =>\n            TryGetElement(root, sourcePath, out var element)\n                ? element\n                : throw new InvalidOperationException($\"Missing required property '{sourcePath}'.\");\n\n        public static bool TryGetElement(JsonElement root, string? sourcePath, out JsonElement element)\n        {\n            element = root;\n            if (string.IsNullOrWhiteSpace(sourcePath))\n            {\n                return true;\n            }\n\n            foreach (var segment in sourcePath!.Split('.'))\n            {\n                if (!element.TryGetProperty(segment, out element))\n                {\n                    return false;\n                }\n            }\n\n            return true;","sourceCodeStart":1,"sourceCodeEnd":30,"githubUrl":"https://github.com/Humanizr/Humanizer/blob/ffc2b77c0f30d2fb176875841424379319d0ae9b/src/Humanizer.SourceGenerators/Common/EngineContractUtilities.cs#L1-L30","documentation":"EngineContractUtilities.GetRequiredElement (EngineContractUtilities.cs:9-12) walks a dot-separated sourcePath through a JSON document and throws if any segment is missing. It is used by engine-contract members that point at a specific location inside resolved locale data; a mismatch between the contract's declared sourcePath and the locale JSON aborts code generation.","triggerScenarios":"An engine-contract member declares a sourcePath (e.g. 'numbers.unitsMap') that does not exist in the locale's resolved JSON, because a segment along the path is absent.","commonSituations":"Locale data was restructured without updating the engine contract; a contract points at a path present only in some locales; a locale is missing a section the contract assumes.","solutions":["Add the missing data at the declared path in the locale file.","Correct the contract's sourcePath to match the actual data layout.","If the path is legitimately optional for some locales, make the contract member optional instead of required."],"exampleFix":"// contract member points at 'numbers.unitsMap'\n// before - locale JSON lacks numbers.unitsMap\n{ \"numbers\": { } }\n// after\n{ \"numbers\": { \"unitsMap\": [\"zero\",\"one\",\"two\"] } }","handlingStrategy":"validation","validationCode":"// Verify a contract sourcePath resolves before generation (C#)\nusing System.Text.Json;\nstatic bool PathExists(JsonElement root, string path) {\n    var el = root;\n    foreach (var seg in path.Split('.'))\n        if (!el.TryGetProperty(seg, out el)) return false;\n    return true;\n}\nif (!PathExists(localeJson, member.SourcePath))\n    throw new InvalidOperationException($\"Contract sourcePath '{member.SourcePath}' not found in locale JSON\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["When restructuring locale data, grep engine contracts for sourcePaths referencing the moved section.","Prefer making locale-specific paths optional in the contract rather than required.","Add a contract self-test that asserts every required sourcePath resolves for every locale."],"tags":["source-generator","build-time","engine-contract","json","localization","locale-data"],"backgroundTag":null,"analyzedSha":"ffc2b77c0f30d2fb176875841424379319d0ae9b","analyzedAt":"2026-08-13T21:42:34.584Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}