{"record":{"id":"62df624992fe5a84","repo":"studyzy/imewlconverter","slug":"error","errorCode":null,"errorMessage":"找不到拼音","messagePattern":"找不到拼音","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/ImeWlConverter.Core/Helpers/ChaoyinHelper.cs","lineNumber":45,"sourceCode":"                    .Split(new[] { '\\r', '\\n' }, StringSplitOptions.RemoveEmptyEntries);\n                foreach (var line in lines)\n                {\n                    var array = line.Split('\\t');\n                    pinyinCodeMapping.Add(array[0], array[1]);\n                    if (array[2] == \"Y\") ShenmuY.Add(array[0]);\n                }\n            }\n\n            return pinyinCodeMapping;\n        }\n    }\n\n    /// <summary>\n    /// 获得一个拼音对应的超音编码\n    /// </summary>\n    public static string? GetChaoyin(string pinyin)\n    {\n        if (string.IsNullOrEmpty(pinyin)) throw new Exception(\"找不到拼音\");\n        var yindiao = 10;\n        if (regex.IsMatch(pinyin))\n        {\n            yindiao = Convert.ToInt32(pinyin[pinyin.Length - 1].ToString());\n            pinyin = pinyin.Substring(0, pinyin.Length - 1);\n        }\n\n        if (!PinyinCodeMapping.ContainsKey(pinyin))\n        {\n            Debug.WriteLine(\"Can not find Chaoyin code by pinyin=\" + pinyin);\n            return null;\n        }\n\n        var zy = PinyinCodeMapping[pinyin];\n        Debug.WriteLine(\"Pinyin:\" + pinyin + \",Chaoyin:\" + zy);\n        return zy;\n    }\n","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/studyzy/imewlconverter/blob/16744a12ed5064896cf39095163e44b367aaada1/src/ImeWlConverter.Core/Helpers/ChaoyinHelper.cs#L27-L63","documentation":"ChaoyinHelper.GetChaoyin(string) converts one pinyin syllable into a Chaoyin (超音速写) code. It throws this bare Exception ONLY as a null/empty precondition guard on the input pinyin. Note the method returns null (does not throw) when the pinyin is well-formed but simply absent from the mapping, so this specific throw means the caller passed NO pinyin at all, not an unknown one.","triggerScenarios":"Calling ChaoyinHelper.GetChaoyin(null) or GetChaoyin(\"\") directly; or indirectly via the overload GetChaoyin(IList<string>) which at line 70 forwards pinyins[0] when the list has one element — if that element is an empty string, the throw fires.","commonSituations":"Running Chaoyin code generation on a word whose pinyin could not be resolved upstream, so an empty pinyin was propagated into the code list. Also when an importer emits a blank pinyin code that is later fed into the Chaoyin generator.","solutions":["Filter empty/whitespace strings out of the pinyin list before calling Chaoyin generation.","Guard each pinyin with string.IsNullOrWhiteSpace(p) and skip the word/code when blank.","Fix upstream pinyin resolution (PinyinHelper) so empty pinyins never reach the generator."],"exampleFix":"// before\nvar code = ChaoyinHelper.GetChaoyin(p);\n// after\nif (string.IsNullOrWhiteSpace(p)) continue;\nvar code = ChaoyinHelper.GetChaoyin(p);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(pinyin)) continue; // or return null\nvar code = ChaoyinHelper.GetChaoyin(pinyin);","typeGuard":null,"tryCatchPattern":"try { var code = ChaoyinHelper.GetChaoyin(p); }\ncatch (Exception ex) when (ex.Message == \"找不到拼音\") { /* skip empty pinyin */ }","preventionTips":["Filter empty/whitespace strings out of word code lists before any code generator runs.","Treat an empty pinyin as 'no code' (skip), never pass it to a conversion helper.","Sanitize importer output so blank pinyin codes never enter the generation pipeline."],"tags":["validation","chaoyin","pinyin","argument"],"backgroundTag":null,"analyzedSha":"16744a12ed5064896cf39095163e44b367aaada1","analyzedAt":"2026-08-13T19:53:09.031Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}