{"record":{"id":"f8cb0d3566c0e0e8","repo":"siyuan-note/siyuan","slug":"document-not-found-s","errorCode":null,"errorMessage":"document not found: %s","messagePattern":"document not found: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/cli/cmd/document.go","lineNumber":121,"sourceCode":"\nfunc normalizeDocumentCreateParentPath(parentPath string) string {\n\tif \"\" == parentPath {\n\t\treturn \"/\"\n\t}\n\treturn strings.TrimSuffix(path.Clean(parentPath), \".sy\")\n}\n\nvar documentGetCmd = &cobra.Command{\n\tUse:   \"get --id <id>\",\n\tShort: \"Get document info\",\n\tRunE: func(cmd *cobra.Command, args []string) error {\n\t\tid, _ := cmd.Flags().GetString(\"id\")\n\t\tif id == \"\" {\n\t\t\treturn fmt.Errorf(\"--id is required\")\n\t\t}\n\t\tbt := treenode.GetBlockTree(id)\n\t\tif bt == nil {\n\t\t\treturn fmt.Errorf(\"document not found: %s\", id)\n\t\t}\n\n\t\ttree, err := model.LoadTreeByBlockID(id)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tblock, err := model.GetBlock(id, tree)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\tswitch outputFormat {\n\t\tcase \"json\":\n\t\t\tdata, _ := json.MarshalIndent(block, \"\", \"  \")\n\t\t\tfmt.Println(string(data))\n\t\tdefault:\n\t\t\tfmt.Printf(\"ID:       %s\\n\", block.ID)\n\t\t\tfmt.Printf(\"Title:    %s\\n\", block.Content)","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/cli/cmd/document.go#L103-L139","documentation":"After the `--id` presence check, `siyuan document get` looks up the ID in the block tree via treenode.GetBlockTree. A nil result means no block/document with that ID exists in the current workspace index, and RunE returns `document not found: <id>`. This distinguishes an ID that was supplied but does not resolve.","triggerScenarios":"Passing an ID that was deleted, belongs to another workspace, was typo'd (wrong checksum suffix), or comes from an unindexed/stale blocktree; querying immediately after external file changes before the kernel reindexed; IDs copied from a different SiYuan instance or an export.","commonSituations":"Stale scripts referencing documents deleted by the user; switching workspaces without updating hardcoded IDs; truncated or hand-edited IDs; docs created outside the running kernel instance (e.g. copied .sy files) that are not yet indexed.","solutions":["Verify the ID via `siyuan document list --notebook <notebookID>` and use a currently existing ID","Confirm you are operating on the intended workspace; blocktree lookup is workspace-scoped","If the document was created externally, let the kernel rescan/index (reopen the workspace or trigger rebuild) and retry","Check for typos in the ID's timestamp/checksum portions; IDs are exact strings"],"exampleFix":"// before\nsiyuan document get --id 20200101120000-doesnotexist\n// after\nID=$(siyuan document list --notebook $NB_ID | head -1)\nsiyuan document get --id \"$ID\"","handlingStrategy":"validation","validationCode":"DOC_ID=$(siyuan document list --notebook \"$NB_ID\" | grep -F \"$DOC_TITLE\" | cut -d' ' -f1)\n[ -n \"$DOC_ID\" ] || { echo \"document not found in notebook\" >&2; exit 1; }\nsiyuan document get --id \"$DOC_ID\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never hardcode document IDs in long-lived scripts; resolve them at runtime","Confirm the workspace matches the one the ID was created in","After external .sy file changes, allow the kernel to reindex before querying","Copy IDs exactly; any character change breaks the lookup"],"tags":["cli","document","not-found","lookup"],"backgroundTag":"entity-not-found","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"}