siyuan-note/siyuan · error

document not found: %s

Error message

document not found: %s

What it means

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.

Source

Thrown at kernel/cli/cmd/document.go:117

func normalizeDocumentCreateParentPath(parentPath string) string {
	if "" == parentPath {
		return "/"
	}
	return strings.TrimSuffix(path.Clean(parentPath), ".sy")
}

var documentGetCmd = &cobra.Command{
	Use:   "get --id <id>",
	Short: "Get document info",
	RunE: func(cmd *cobra.Command, args []string) error {
		id, _ := cmd.Flags().GetString("id")
		if id == "" {
			return fmt.Errorf("--id is required")
		}
		bt := treenode.GetBlockTree(id)
		if bt == nil {
			return fmt.Errorf("document not found: %s", id)
		}

		tree, err := model.LoadTreeByBlockID(id)
		if err != nil {
			return err
		}
		block, err := model.GetBlock(id, tree)
		if err != nil {
			return err
		}

		switch outputFormat {
		case "json":
			data, _ := json.MarshalIndent(block, "", "  ")
			fmt.Println(string(data))
		default:
			fmt.Printf("ID:       %s\n", block.ID)
			fmt.Printf("Title:    %s\n", block.Content)

View on GitHub (pinned to 251596fc0d)

Solutions

  1. Confirm the ID exists in the current workspace: `siyuan document list --notebook <id>` and find the document, or search by keyword.
  2. Ensure the workspace is correct (`--workspace` / boot dir) and the kernel has finished indexing.
  3. Remove any whitespace/newlines around the ID before passing it.
  4. If the document was deleted, restore from history or use a known-good ID.
  5. For a closed notebook, open it in the UI first so its blocktree entries load.

Example fix

// before
siyuan document get --id 20240101000000-wrong
// after
# look up the real id first
siyuan document search "meeting notes"
siyuan document get --id 20240101000000-abc1234
Defensive patterns

Strategy: validation

Validate before calling

# confirm the block exists before get
siyuan document search "<keyword>" | grep -q "$DOC_ID" || { echo "id not found in workspace; verify workspace and indexing" >&2; exit 2; }
siyuan document get --id "$DOC_ID"

Type guard

// Go: existence check via the blocktree before deeper load
func blockExists(id string) bool { return treenode.GetBlockTree(id) != nil }

Try / catch

if ! siyuan document get --id "$DOC_ID" 2>err.txt; then
  grep -q 'not found' err.txt && echo "no block for $DOC_ID in this workspace" >&2
  exit 1
fi

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of siyuan-note/siyuan@251596fc0d (2026-08-12). Data as JSON: /api/errors/f8cb0d3566c0e0e8. Report an issue: GitHub.