{"record":{"id":"f8cb0d3566c0e0e8","repo":"siyuan-note/siyuan","slug":"document-not-found-s","errorCode":null,"errorMessage":"document not found: %s","messagePattern":"document not found: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/cli/cmd/document.go","lineNumber":117,"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":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/251596fc0de2f9528c00c224252fd073a99973f4/kernel/cli/cmd/document.go#L99-L135","documentation":"The `document get` handler calls treenode.GetBlockTree(id) to look up the block's metadata in the in-memory blocktree (backed by blocktree.db). If the lookup returns nil — meaning no block with that ID is registered — the handler returns this error. This is a runtime/data error, not a flag error: it fires after --id passes the empty check but the ID does not correspond to any known block in the current workspace.","triggerScenarios":"Passing a plausible-looking but non-existent ID; referencing an ID from a different workspace; using an ID of a block that was deleted (and its blocktree entry removed); passing an ID with a typo in the suffix; querying before the kernel has finished indexing the blocktree; passing an ID format that does not match the stored key.","commonSituations":"Workspace mismatch (ID from workspace A queried in workspace B); recently deleted document whose blocktree entry was pruned; copy-paste truncation of the ID; querying during/after a sync that has not yet rebuilt the blocktree; leading/trailing whitespace or a stray newline in the ID; referencing a block from a notebook that is closed.","solutions":["Confirm the ID exists in the current workspace: `siyuan document list --notebook <id>` and find the document, or search by keyword.","Ensure the workspace is correct (`--workspace` / boot dir) and the kernel has finished indexing.","Remove any whitespace/newlines around the ID before passing it.","If the document was deleted, restore from history or use a known-good ID.","For a closed notebook, open it in the UI first so its blocktree entries load."],"exampleFix":"// before\nsiyuan document get --id 20240101000000-wrong\n// after\n# look up the real id first\nsiyuan document search \"meeting notes\"\nsiyuan document get --id 20240101000000-abc1234","handlingStrategy":"validation","validationCode":"# confirm the block exists before get\nsiyuan document search \"<keyword>\" | grep -q \"$DOC_ID\" || { echo \"id not found in workspace; verify workspace and indexing\" >&2; exit 2; }\nsiyuan document get --id \"$DOC_ID\"","typeGuard":"// Go: existence check via the blocktree before deeper load\nfunc blockExists(id string) bool { return treenode.GetBlockTree(id) != nil }","tryCatchPattern":"if ! siyuan document get --id \"$DOC_ID\" 2>err.txt; then\n  grep -q 'not found' err.txt && echo \"no block for $DOC_ID in this workspace\" >&2\n  exit 1\nfi","preventionTips":["Confirm the workspace/boot directory matches where the ID originated.","Wait for kernel indexing to finish before querying freshly imported docs.","Strip whitespace from IDs copied from URLs or other tools."],"tags":["cli","cobra","document","block-id","blocktree","data-lookup","go"],"backgroundTag":null,"analyzedSha":"251596fc0de2f9528c00c224252fd073a99973f4","analyzedAt":"2026-08-12T21:18:37.123Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}