{"record":{"id":"5f7e143721022304","repo":"Humanizr/Humanizer","slug":"inflection-subject-contains-invalid-unicode","errorCode":null,"errorMessage":"Inflection {subject} contains invalid Unicode.","messagePattern":"Inflection (.+?) contains invalid Unicode\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Humanizer.SourceGenerators/Generators/ProfileCatalogs/InflectionCatalogValidation.cs","lineNumber":232,"sourceCode":"\n        static string NormalizeAuthoredText(\n            string value,\n            string casing,\n            ImmutableArray<string> ownerScripts,\n            string subject,\n            bool allowStemPlaceholder,\n            bool allowNonLetters)\n        {\n            string normalized;\n            try\n            {\n                normalized = value.IsNormalized(NormalizationForm.FormC)\n                    ? value\n                    : value.Normalize(NormalizationForm.FormC);\n            }\n            catch (ArgumentException)\n            {\n                throw new InvalidOperationException(\n                    $\"Inflection {subject} contains invalid Unicode.\");\n            }\n\n            if (casing == \"lower-title-upper\")\n            {\n                if (!TryNormalizeSimpleLower(normalized, out var lower))\n                {\n                    throw new InvalidOperationException(\n                        $\"Inflection {subject} has an unsupported casing expansion.\");\n                }\n\n                normalized = lower;\n            }\n\n            var literal = allowStemPlaceholder\n                ? normalized.Replace(\"{stem}\", string.Empty)\n                : normalized;\n            if (literal.Length > 0 &&","sourceCodeStart":214,"sourceCodeEnd":250,"githubUrl":"https://github.com/Humanizr/Humanizer/blob/ffc2b77c0f30d2fb176875841424379319d0ae9b/src/Humanizer.SourceGenerators/Generators/ProfileCatalogs/InflectionCatalogValidation.cs#L214-L250","documentation":"The validator attempts NFC normalization of authored text and catches ArgumentException. If normalization fails — typically because the string contains unpaired UTF-16 surrogates or other invalid Unicode sequences — the error is rethrown with a descriptive message naming the subject that failed.","triggerScenarios":"An authored text value in the locale YAML contains a malformed Unicode sequence that causes value.Normalize(NormalizationForm.FormC) to throw ArgumentException. This happens with lone surrogate halves (U+D800-U+DFFF without their pair) or other ill-formed code unit sequences.","commonSituations":"Pasting text from an external tool that introduced lone surrogates. Encoding issues when saving the YAML file (wrong BOM, mojibake). Manual editing that accidentally inserts a surrogate-half character.","solutions":["Inspect the offending YAML value for invalid Unicode — use a hex editor or Unicode inspector to find lone surrogates.","Replace the malformed sequence with the correct character (e.g., use the precomposed form or a proper surrogate pair).","Re-save the locale YAML file as UTF-8 without BOM using a reliable editor to eliminate encoding corruption."],"exampleFix":"# before — contains lone high surrogate U+D800\naccepted:\n  - 'word\\uD800'\n# after\naccepted:\n  - 'word'","handlingStrategy":"validation","validationCode":"# Before building, scan locale YAML for strings with invalid Unicode (lone surrogates).\npython3 -c \"\nimport yaml, sys\nfor f in sys.argv[1:]:\n    raw = open(f, encoding='utf-8').read()\n    for i, ch in enumerate(raw):\n        cp = ord(ch)\n        if 0xD800 <= cp <= 0xDFFF:\n            print(f'{f}: lone surrogate U+{cp:04X} at position {i}')\n\" src/Humanizer/Locales/*.yml","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always save locale YAML as well-formed UTF-8 without lone surrogates.","Avoid pasting text from terminals or tools that may corrupt encoding.","Run a Unicode validation script in CI that rejects files with lone surrogates."],"tags":["inflection","source-generator","normalization","unicode","encoding","yaml","build-time"],"backgroundTag":null,"analyzedSha":"ffc2b77c0f30d2fb176875841424379319d0ae9b","analyzedAt":"2026-08-13T21:42:34.584Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}