siyuan-note/siyuan · error

document not found

Error message

document not found: %s

What it means

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.

Solutions

  1. Verify the ID via `siyuan document list --notebook <notebookID>` and use a currently existing ID
  2. Confirm you are operating on the intended workspace; blocktree lookup is workspace-scoped
  3. If the document was created externally, let the kernel rescan/index (reopen the workspace or trigger rebuild) and retry
  4. Check for typos in the ID's timestamp/checksum portions; IDs are exact strings

Example fix

// before
siyuan document get --id 20200101120000-doesnotexist
// after
ID=$(siyuan document list --notebook $NB_ID | head -1)
siyuan document get --id "$ID"
Defensive patterns

Strategy: validation

Validate before calling

DOC_ID=$(siyuan document list --notebook "$NB_ID" | grep -F "$DOC_TITLE" | cut -d' ' -f1)
[ -n "$DOC_ID" ] || { echo "document not found in notebook" >&2; exit 1; }
siyuan document get --id "$DOC_ID"

Prevention

When it happens

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

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

Understand the failure class

Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/f8cb0d3566c0e0e8. Report an issue: GitHub.

Appendix: source

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

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 9f775e8a12)