{"record":{"id":"d52471af38115b48","repo":"siyuan-note/siyuan","slug":"document-not-found-or-empty","errorCode":null,"errorMessage":"document not found or empty","messagePattern":"document not found or empty","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/cli/cmd/block.go","lineNumber":168,"sourceCode":"\t\tif mode == \"\" {\n\t\t\tmode = \"md\"\n\t\t}\n\t\tfmt.Print(model.GetBlockKramdown(id, mode))\n\t\treturn nil\n\t},\n}\n\nvar blockStatCmd = &cobra.Command{\n\tUse:   \"stat --id <id>\",\n\tShort: \"Get block content statistics\",\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\tstat := filesys.StatTree(id)\n\t\tif stat == nil {\n\t\t\treturn fmt.Errorf(\"document not found or empty\")\n\t\t}\n\t\tswitch outputFormat {\n\t\tcase \"json\":\n\t\t\tdata, _ := json.MarshalIndent(stat, \"\", \"  \")\n\t\t\tfmt.Println(string(data))\n\t\tdefault:\n\t\t\tfmt.Printf(\"Characters: %d\\n\", stat.RuneCount)\n\t\t\tfmt.Printf(\"Words:      %d\\n\", stat.WordCount)\n\t\t\tfmt.Printf(\"Blocks:     %d\\n\", stat.BlockCount)\n\t\t\tfmt.Printf(\"Links:      %d\\n\", stat.LinkCount)\n\t\t\tfmt.Printf(\"Images:     %d\\n\", stat.ImageCount)\n\t\t\tfmt.Printf(\"Refs:       %d\\n\", stat.RefCount)\n\t\t}\n\t\treturn nil\n\t},\n}\n\n// ─── Write ─────────────────────────────────────────────────────────────────────","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/cli/cmd/block.go#L150-L186","documentation":"The `block info` CLI command fails when `filesys.StatTree(id)` returns nil, meaning no document tree exists for the given --id or the document is empty. The CLI requires a resolvable document before it can report statistics.","triggerScenarios":"Running `siyuan block info --id <id>` where the id is not an existing document ID (typo, wrong notebook, block deleted) or points to a document whose tree fails to load / is empty.","commonSituations":"Copy-pasting a block ID instead of a document ID; using an ID from a notebook not present in the workspace; the document was deleted or renamed by another session; passing a synthetic/invalid ID.","solutions":["Verify the --id is a valid document ID from an existing notebook in the current workspace (check the .sy filename under data/<notebook>/).","List documents to find the correct ID (e.g. inspect data/<notebookID>/*.sy files) and retry with the correct document ID.","Confirm the kernel workspace is correct so StatTree looks in the right data directory.","If the document exists but is empty, add content to it or use a non-empty document."],"exampleFix":"// before\nsiyuan block info --id 20240101120000-abcdefg\n// after\nsiyuan block info --id 20240101120000-h1x2y3z  # actual .sy doc ID in the workspace","handlingStrategy":"validation","validationCode":"if [ -z \"$DOC_ID\" ]; then echo \"--id required\" >&2; exit 1; fi\nsiyuan block info --id \"$DOC_ID\" || { echo \"document $DOC_ID not found in workspace\" >&2; exit 1; }","typeGuard":null,"tryCatchPattern":"out=$(siyuan block info --id \"$DOC_ID\" 2>&1) || { echo \"$out\"; exit 1; }","preventionTips":["Copy document IDs from the .sy filename, not from block refs","Confirm the kernel workspace matches the notebook's data directory","Check the document is non-empty before querying stats"],"tags":["cli","document","not-found"],"backgroundTag":"resource-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"}