{"record":{"id":"a6e4aef009953201","repo":"studyzy/imewlconverter","slug":"c-a6e4ae","errorCode":null,"errorMessage":"找不到字:'{c}'的拼音","messagePattern":"找不到字:'(.+?)'的拼音","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/ImeWlConverter.Core/Helpers/PinyinHelper.cs","lineNumber":27,"sourceCode":"    /// 获得一个字的默认拼音(不包含音调)\n    /// </summary>\n    public static string GetDefaultPinyin(char c)\n    {\n        try\n        {\n            if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))\n            {\n                return c.ToString().ToLower();\n            }\n\n            if (c >= '0' && c <= '9')\n            {\n                return c.ToString();\n            }\n\n            var pys = PinYinDict[c];\n            if (pys != null && pys.Count > 0) return pys[0];\n            throw new Exception($\"找不到字:'{c}'的拼音\");\n        }\n        catch\n        {\n            throw new Exception($\"找不到字:'{c}'的拼音\");\n        }\n    }\n\n    public static IList<string> GetDefaultPinyin(string word)\n    {\n        var result = new List<string>();\n        var si = new StringInfo(word);\n        for (int i = 0; i < si.LengthInTextElements; i++)\n        {\n            var textElement = si.SubstringByTextElements(i, 1);\n            if (textElement.Length == 1)\n            {\n                result.Add(GetDefaultPinyin(textElement[0]));\n            }","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/studyzy/imewlconverter/blob/16744a12ed5064896cf39095163e44b367aaada1/src/ImeWlConverter.Core/Helpers/PinyinHelper.cs#L9-L45","documentation":"PinyinHelper.GetDefaultPinyin(char) returns the first pinyin of a character. THIS throw (line 27, inside the try) fires only when the character IS present in PinYinDict but its pinyin list is null or empty — i.e. the dictionary entry exists yet carries no usable pinyin. This is a data-integrity edge, not a normal input case (contrast with error [5]).","triggerScenarios":"Calling GetDefaultPinyin for a character that exists in ChineseCode.txt with an empty pinyin column; a corrupted/truncated embedded ChineseCode.txt resource where a row has a blank pinyin field.","commonSituations":"A modified or corrupted embedded ChineseCode.txt resource; extremely unusual with the shipped data since all rows normally carry pinyin.","solutions":["Rebuild/restore the project so the embedded ChineseCode.txt resource is intact.","Pre-check: use PinYinDict.TryGetValue(c, out var pys) && pys is { Count: > 0 } before calling.","Wrap the call in try/catch and skip the character."],"exampleFix":"// before\nvar py = PinyinHelper.GetDefaultPinyin(c);\n// after\nif (PinyinHelper.PinYinDict.TryGetValue(c, out var pys) && pys is { Count: > 0 })\n    var py = pys[0];\nelse\n    continue;","handlingStrategy":"validation","validationCode":"if (PinyinHelper.PinYinDict.TryGetValue(c, out var pys) && pys is { Count: > 0 })\n    var py = pys[0];\nelse continue;","typeGuard":null,"tryCatchPattern":"try { var py = PinyinHelper.GetDefaultPinyin(c); }\ncatch (Exception ex) when (ex.Message.StartsWith(\"找不到字\")) { /* skip */ }","preventionTips":["Keep the embedded ChineseCode.txt resource intact; rebuild if you suspect corruption.","For any custom ChineseCode.txt, ensure every row has a non-empty pinyin column.","Pre-check TryGetValue + non-empty list rather than relying on the indexer."],"tags":["pinyin","lookup","cjk","dictionary","data-integrity"],"backgroundTag":null,"analyzedSha":"16744a12ed5064896cf39095163e44b367aaada1","analyzedAt":"2026-08-13T19:53:09.031Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}