{"record":{"id":"19064246e81620c9","repo":"wmjordan/PDFPatcher","slug":"linenum","errorCode":null,"errorMessage":"在简易书签第 {lineNum} 行的缩进格式不正确。\n\n说明：下级书签最多只能比上级书签多一个缩进标记。","messagePattern":"在简易书签第 (.+?) 行的缩进格式不正确。\n\n说明：下级书签最多只能比上级书签多一个缩进标记。","errorType":"validation","errorClass":"FormatException","httpStatus":null,"severity":"error","filePath":"App/Processor/OutlineManager.cs","lineNumber":132,"sourceCode":"\t\t\t\t\tpageNum = 0;\r\n\t\t\t\t}\r\n\t\t\t\telse {\r\n\t\t\t\t\tif (pnText.IndexOfAny(__fullWidthNumbers) != -1) {\r\n\t\t\t\t\t\tdigits = Array.ConvertAll(m.Groups[2].Value.ToCharArray(), d => ValueHelper.MapValue(d, __fullWidthNumbers, __halfWidthNumbers, d));\r\n\t\t\t\t\t\tpnText = new string(digits, 0, digits.Length);\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif (pnText.TryParse(out pageNum)) {\r\n\t\t\t\t\t\tpageNum += pageOffset;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tbookmark = target.CreateBookmark();\r\n\t\t\t\tif (indent == currentIndent) {\r\n\t\t\t\t\tcurrentBookmark.ParentNode.AppendChild(bookmark);\r\n\t\t\t\t}\r\n\t\t\t\telse if (indent > currentIndent) {\r\n\t\t\t\t\tcurrentBookmark.AppendChild(bookmark);\r\n\t\t\t\t\tif (indent - currentIndent > 1) {\r\n\t\t\t\t\t\tthrow new FormatException($\"在简易书签第 {lineNum} 行的缩进格式不正确。\\n\\n说明：下级书签最多只能比上级书签多一个缩进标记。\");\r\n\t\t\t\t\t}\r\n\t\t\t\t\tcurrentIndent++;\r\n\t\t\t\t}\r\n\t\t\t\telse /* indent < currentIndent */ {\r\n\t\t\t\t\twhile (currentIndent > indent && currentBookmark.ParentNode != root) {\r\n\t\t\t\t\t\tcurrentBookmark = currentBookmark.ParentNode as BookmarkContainer;\r\n\t\t\t\t\t\tcurrentIndent--;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tcurrentBookmark.ParentNode.AppendChild(bookmark);\r\n\t\t\t\t}\r\n\t\t\t\tbookmark.Title = title;\r\n\t\t\t\tif (!isOpen) {\r\n\t\t\t\t\tbookmark.IsOpen = false;\r\n\t\t\t\t}\r\n\t\t\t\tif (pageNum > 0) {\r\n\t\t\t\t\tbookmark.Page = pageNum;\r\n\t\t\t\t}\r\n\t\t\t\tcurrentBookmark = bookmark;\r","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/wmjordan/PDFPatcher/blob/4782bbd9ada850b56258f29999b7a1c9076c9b1b/App/Processor/OutlineManager.cs#L114-L150","documentation":"Thrown as FormatException by ImportSimpleBookmarks when a parsed bookmark line's indentation increases by more than one level relative to currentIndent. The simple-bookmark format encodes hierarchy purely through repeated indent markers (tab by default, configurable via the 缩进标记 command); a child may be exactly one level deeper than its parent, never two or more. The message names the offending 1-based line number (lineNum) so the user can locate it.","triggerScenarios":"A line whose leading indentString count minus currentIndent is > 1. Example: currentIndent==0 and the next bookmark line begins with two or more tabs/spaces. Also triggered when the indent string was redefined mid-file with 缩进标记 and earlier lines were parsed under the old string, or when tabs and spaces are mixed so IndexOf(indentString) miscounts.","commonSituations":"Hand-edited or pasted bookmark files with inconsistent nesting; files indented with spaces while the parser expects tabs (or vice-versa); deeply-nested bookmarks where a parent was deleted but children kept their old indent; a 缩进标记 change that makes previously-valid lines over-indented relative to the new marker.","solutions":["Open the file at the reported line number and reduce its leading indent to exactly one marker beyond its intended parent.","Normalize the whole file to a single indent character (tabs or spaces) and ensure each nesting level adds exactly one marker.","If the indent string differs from tabs, add a single #缩进标记=<marker> directive at the top BEFORE any bookmarks and verify it applies to the whole file.","Pre-validate by scanning lines and asserting each indent step is <= 1 before calling ImportSimpleBookmarks."],"exampleFix":"// before (jumps from level 0 to level 2)\n第一章\t1\n\t\t1.1 节\t2\n\n// after (single-step indent)\n第一章\t1\n\t1.1 节\t2","handlingStrategy":"validation","validationCode":"static void ValidateSimpleBookmarkIndents(string path, string indentString) {\n    int current = -1;\n    int lineNum = 0;\n    foreach (var raw in File.ReadLines(path)) {\n        lineNum++;\n        if (string.IsNullOrWhiteSpace(raw)) continue;\n        if (raw[0] == '#' || raw[0] == '＃') continue;\n        int p = 0, ind = 0;\n        while (raw.IndexOf(indentString, p) == p) { p += indentString.Length; ind++; }\n        if (current >= 0 && ind - current > 1)\n            throw new FormatException($\"第 {lineNum} 行缩进跳跃过大：{ind} > {current}+1\");\n        if (ind > current) current = ind;\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    OutlineManager.ImportSimpleBookmarks(path, doc);\n}\ncatch (FormatException ex) when (ex.Message.Contains(\"缩进格式不正确\")) {\n    FormHelper.ErrorBox(ex.Message + \"\\n请检查对应行的缩进标记。\");\n}","preventionTips":["Use a single, consistent indent character (tabs) for the whole file; do not mix tabs and spaces.","If you change the indent marker, place #缩进标记=<marker> on the first line and rebuild the file under it.","When editing by hand, ensure each nested level adds exactly one marker; pre-validate before import."],"tags":["pdf","bookmarks","parsing","indentation","format-exception","csharp"],"backgroundTag":null,"analyzedSha":"4782bbd9ada850b56258f29999b7a1c9076c9b1b","analyzedAt":"2026-08-13T17:44:50.812Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}