siyuan-note/siyuan · error

block not found

Error message

block not found: %s

What it means

Lookup failure in the cobra blockDelete RunE: treenode.GetBlockTree found no block tree entry for the --id value, meaning the ID does not exist in the index (typo, stale ID, or deleted block). The error wraps the offending ID via fmt.Errorf %s; verify the block ID exists before deleting.

Solutions

  1. Verify the block ID exists (block info --id <id> or check the .sy file content).
  2. Re-list blocks to refresh IDs if the notebook was reindexed or synced since capture.
  3. Confirm the CLI runs against the intended workspace so GetBlockTree loads the right data.
  4. Handle already-deleted IDs idempotently in scripts (ignore block-not-found).

Example fix

// before
siyuan block delete --id 20240101120000-olddoc1
// error: block not found: 20240101120000-olddoc1
// after
siyuan block info --id 20240101120000-olddoc1 || echo "already gone; skipping"
siyuan block delete --id 20240101120000-olddoc1
Defensive patterns

Strategy: try-catch

Validate before calling

siyuan block info --id "$BLOCK_ID" >/dev/null 2>&1 || { echo "block $BLOCK_ID does not exist; skipping" >&2; exit 0; }

Try / catch

if ! siyuan block delete --id "$BLOCK_ID"; then
  case "${BLOCK_ID}" in *) echo "delete failed; check block exists" >&2;; esac
fi

Prevention

When it happens

Trigger: Running `siyuan block delete --id <id>` where <id> does not correspond to any indexed block (typo, already deleted, wrong workspace, ID of a non-sy asset).

Common situations: Deleting a block that a previous script run already removed; stale IDs captured before a reindex or sync; workspace path pointing at a different data directory.

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/afb59e4d0d1d56ba. Report an issue: GitHub.

Appendix: source

Thrown at kernel/cli/cmd/block.go:384

			model.AppendPushReloadProtyleEntry(rootID)
		}
		fmt.Println("ok")
		return nil
	},
}

var blockDeleteCmd = &cobra.Command{
	Use:   "delete --id <id>",
	Short: "Delete block",
	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("block not found: %s", id)
		}
		if dryRun {
			fmt.Printf("[dry-run] Would delete block %s\n", id)
			return nil
		}

		transactions := []*model.Transaction{{
			DoOperations: []*model.Operation{{
				Action: "delete",
				ID:     id,
			}},
		}}
		model.PerformTransactions(&transactions)
		model.FlushTxQueue()

		if bt != nil {
			model.AppendPushReloadProtyleEntry(bt.RootID)
		}

View on GitHub (pinned to 9f775e8a12)