{"record":{"id":"051f0f2a58376e73","repo":"siyuan-note/siyuan","slug":"parse-tree-s-failed","errorCode":null,"errorMessage":"parse tree [%s] failed","messagePattern":"parse tree \\[(.+?)\\] failed","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/import.go","lineNumber":1805,"sourceCode":"\t\tif !strings.HasSuffix(fileName, \".md\") && !strings.HasSuffix(fileName, \".markdown\") {\n\t\t\treturn errors.New(Conf.Language(79))\n\t\t}\n\n\t\ttitle := strings.TrimSuffix(fileName, \".markdown\")\n\t\ttitle = strings.TrimSuffix(title, \".md\")\n\t\ttargetPath := strings.TrimSuffix(toPath, \".sy\")\n\t\tid := ast.NewNodeID()\n\t\ttargetPath = path.Join(targetPath, id+\".sy\")\n\t\tvar data []byte\n\t\tdata, err = os.ReadFile(localPath)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\ttree, yfmRootID, yfmTitle, yfmUpdated := parseStdMd(data)\n\t\tif nil == tree {\n\t\t\tmsg := fmt.Sprintf(\"parse tree [%s] failed\", localPath)\n\t\t\tlogging.LogError(msg)\n\t\t\treturn errors.New(msg)\n\t\t}\n\n\t\tif \"\" != yfmRootID {\n\t\t\tid = yfmRootID\n\t\t}\n\t\tif \"\" != yfmTitle {\n\t\t\ttitle = yfmTitle\n\t\t}\n\t\tunescapedTitle, unescapeErr := url.PathUnescape(title)\n\t\tif nil == unescapeErr {\n\t\t\ttitle = unescapedTitle\n\t\t}\n\t\tupdated := yfmUpdated\n\t\tfname := path.Base(targetPath)\n\t\ttargetPath = strings.ReplaceAll(targetPath, fname, id+\".sy\")\n\n\t\ttree.ID = id\n\t\ttree.Root.ID = id","sourceCodeStart":1787,"sourceCodeEnd":1823,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/import.go#L1787-L1823","documentation":"After reading the file, `importFromLocalPath` parses it with `parseStdMd` (Lute). If the parser returns a nil tree, the kernel logs and returns `parse tree [<localPath>] failed` to the caller. This means the file content could not be built into a valid Markdown AST — typically an unreadable/empty file or content Lute rejected at the parse stage.","triggerScenarios":"Calling the import API with an `.md`/`.markdown` file whose bytes produce a nil tree from `parseStdMd` — e.g. empty file, binary content with an `.md` extension, or an encoding Lute cannot handle.","commonSituations":"Renamed binary files (PDF/zip renamed to `.md`); zero-byte exports from other tools; files in non-UTF-8 encodings (GBK, UTF-16) whose bytes break parsing; corrupted downloads.","solutions":["Verify the file is real UTF-8 Markdown text (`file`, `head`, or opening it in an editor); re-export if it is binary or wrong encoding","Check the kernel log for the logged `parse tree [...] failed` line to confirm which path failed, then inspect that exact file","Convert the file to UTF-8 and remove corrupted content, then retry the import"],"exampleFix":"// before\n// importing a UTF-16 encoded file exported by another tool\nimportFromLocalPath(\"/notes/doc.md\", toPath) // parse tree [/notes/doc.md] failed\n// after\n// re-save the file as UTF-8 plain Markdown, then import\nimportFromLocalPath(\"/notes/doc-utf8.md\", toPath)","handlingStrategy":"validation","validationCode":"const buf = await fs.readFile(localPath);\nconst text = buf.toString(\"utf8\");\nif (text.length === 0 || /\\u0000/.test(text.slice(0, 512))) {\n  throw new Error(\"File is empty or binary; not importable Markdown\");\n}","typeGuard":"function looksLikeTextMarkdown(buf: Buffer): boolean {\n  return buf.length > 0 && !buf.subarray(0, 512).includes(0);\n}","tryCatchPattern":"try {\n  await api.importFromLocalPath(localPath, toPath);\n} catch (e) {\n  if (String(e.message).startsWith(\"parse tree\")) {\n    // re-encode file to UTF-8 and retry, or skip and report to user\n  }\n}","preventionTips":["Ensure exports are UTF-8 plain-text Markdown before import","Never rename binary files to .md; verify content with a text editor","Check kernel logs for the 'parse tree [...] failed' entry to identify the bad file"],"tags":["import","parse-error","markdown","lute"],"backgroundTag":"invalid-argument-format","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}