studyzy/imewlconverter · error · Exception
无效的自定义编码格式:{line}
Error message
无效的自定义编码格式:{line} What it means
UserCodingHelper.GetCodingDict loads a user-supplied custom code-mapping file for the user-defined coding generator. Each non-empty line MUST be exactly two tab-separated fields (character, code). Any line that does not split into exactly 2 tab-fields throws, reporting the offending line.
Source
Thrown at src/ImeWlConverter.Core/Helpers/UserCodingHelper.cs:22
public static class UserCodingHelper
{
public static IDictionary<char, IList<string>> GetCodingDict(
string filePath,
Encoding encoding
)
{
var codingContent = FileOperationHelper.ReadFile(filePath, encoding);
var dic = new Dictionary<char, IList<string>>();
foreach (
var line in codingContent.Split(
new[] { '\r', '\n' },
StringSplitOptions.RemoveEmptyEntries
)
)
{
var l = line.Split('\t');
if (l.Length != 2) throw new Exception("无效的自定义编码格式:" + line);
var c = l[0][0];
var code = l[1];
if (!dic.ContainsKey(c))
dic.Add(c, new List<string> { code });
else
dic[c].Add(code);
}
return dic;
}
}
View on GitHub (pinned to 16744a12ed)
Solutions
- Open the file and confirm every line is exactly `char<TAB>code` with a single tab and no trailing tab.
- Convert any space/comma delimiters to a single tab; remove stray tabs.
- If a different delimiter is intended, pre-process the file to tab-separated before passing it in.
Example fix
// before (file content, space-delimited) // a b // after (tab-delimited) // a\tb
Defensive patterns
Strategy: validation
Validate before calling
foreach (var line in lines)
if (line.Split('\t').Length != 2)
throw new FormatException($"bad line (expected 1 tab): {line}"); Try / catch
try { var dic = UserCodingHelper.GetCodingDict(path, enc); }
catch (Exception ex) { ReportError($"custom coding file invalid: {ex.Message}"); } Prevention
- Document the exact TSV format (one tab, two fields) for user coding files.
- Dry-run validate the file (count tabs per line) before the full conversion.
- Normalize delimiters (spaces/commas to a single tab) in a pre-processing step.
When it happens
Trigger: A custom coding file using spaces, commas, or multiple tabs instead of exactly one tab as delimiter; a line with a single field; a line with three or more tab fields; a stray trailing tab that creates an empty third field.
Common situations: User hand-edited the mapping file and used spaces instead of tabs; file exported from Excel/spreadsheet as CSV rather than TSV; mixed delimiters; a comment line that survived the empty-line removal.
AI-assisted analysis of studyzy/imewlconverter@16744a12ed (2026-08-13).
Data as JSON: /api/errors/e757f102fc65e551.
Report an issue: GitHub.