{"record":{"id":"5ba918d6c8190411","repo":"wmjordan/PDFPatcher","slug":"error-5ba918","errorCode":null,"errorMessage":"简易书签文件内容不足。","messagePattern":"简易书签文件内容不足。","errorType":"validation","errorClass":"FormatException","httpStatus":null,"severity":"error","filePath":"App/Processor/OutlineManager.cs","lineNumber":197,"sourceCode":"\t\t\t\tfor (int i = 0; i < indent; i++) {\r\n\t\t\t\t\twriter.Write(indentChar);\r\n\t\t\t\t}\r\n\t\t\t\twriter.Write(item.Title);\r\n\t\t\t\twriter.Write(\"\\t\\t\");\r\n\t\t\t\twriter.Write(item.Page.ToText());\r\n\t\t\t\twriter.WriteLine();\r\n\t\t\t\tWriteSimpleBookmark(writer, item, indent + 1, indentChar);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tprivate static Encoding DetectEncoding(string path) {\r\n\t\t\tconst string VersionString = \"#版本\";\r\n\t\t\tconst string VersionString2 = \"＃版本\";\r\n\r\n\t\t\tvar b = new byte[20];\r\n\t\t\tusing (var r = new FileStream(path, FileMode.Open)) {\r\n\t\t\t\tif (r.Length < b.Length) {\r\n\t\t\t\t\tthrow new FormatException(\"简易书签文件内容不足。\");\r\n\t\t\t\t}\r\n\t\t\t\tr.Read(b, 0, b.Length);\r\n\t\t\t}\r\n\t\t\tforeach (var item in Constants.Encoding.Encodings) {\r\n\t\t\t\tif (item == null) {\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\t}\r\n\t\t\t\tvar s = item.GetString(b);\r\n\t\t\t\tif (s.HasPrefix(VersionString) || s.HasPrefix(VersionString2)) {\r\n\t\t\t\t\treturn item;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn Encoding.Default;\r\n\t\t}\r\n\r\n\t}\r\n}\r\n","sourceCodeStart":179,"sourceCodeEnd":215,"githubUrl":"https://github.com/wmjordan/PDFPatcher/blob/4782bbd9ada850b56258f29999b7a1c9076c9b1b/App/Processor/OutlineManager.cs#L179-L215","documentation":"Thrown as FormatException by DetectEncoding when the selected bookmark file is shorter than 20 bytes. DetectEncoding reads the first 20 bytes (new byte[20]) to probe for the version marker #版本 / ＃版本 across the candidate encodings in Constants.Encoding.Encodings; with fewer than 20 bytes the probe is meaningless so it refuses to guess. The threshold is the fixed buffer length b.Length, not a content heuristic.","triggerScenarios":"ImportSimpleBookmarks(path,...) -> DetectEncoding(path) where the FileStream reports r.Length < 20. Caused by an empty file, a file containing only a few characters, a Windows shortcut/partial download, or selecting a non-bookmark text file by mistake.","commonSituations":"User picks an empty or near-empty file in the bookmark-import dialog; a file that failed to finish writing/syncing; selecting a .lnk or tiny placeholder instead of the real bookmark file; a bookmark export that wrote zero bytes due to an earlier error.","solutions":["Check the file size before import: if new FileInfo(path).Length < 20, reject it with a clear message.","Re-export the bookmarks from the source document, or re-download/recreate the file and confirm it contains the #版本 header.","Verify the selected path points to the actual bookmark text file and not a shortcut or 0-byte stub."],"exampleFix":"// before\nOutlineManager.ImportSimpleBookmarks(path, doc);\n\n// after\nif (!File.Exists(path) || new FileInfo(path).Length < 20) {\n    FormHelper.ErrorBox(\"简易书签文件为空或内容不足，请选择有效的书签文件。\");\n    return;\n}\nOutlineManager.ImportSimpleBookmarks(path, doc);","handlingStrategy":"validation","validationCode":"if (!File.Exists(path) || new FileInfo(path).Length < 20) {\n    FormHelper.ErrorBox(\"简易书签文件为空或内容不足，请选择有效的书签文件。\");\n    return;\n}","typeGuard":null,"tryCatchPattern":"try {\n    OutlineManager.ImportSimpleBookmarks(path, doc);\n}\ncatch (FormatException ex) when (ex.Message.Contains(\"内容不足\")) {\n    FormHelper.ErrorBox(\"所选书签文件内容不足 20 字节，无法识别编码。\");\n}","preventionTips":["Confirm the selected file is the exported bookmark file and contains the #版本 header.","Re-export from the source document if the file is empty or truncated.","Avoid selecting shortcuts (.lnk) or 0-byte placeholders in the import dialog."],"tags":["pdf","bookmarks","file-io","encoding-detection","format-exception","csharp"],"backgroundTag":null,"analyzedSha":"4782bbd9ada850b56258f29999b7a1c9076c9b1b","analyzedAt":"2026-08-13T17:44:50.812Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}