{"record":{"id":"afb59e4d0d1d56ba","repo":"siyuan-note/siyuan","slug":"block-not-found-s","errorCode":null,"errorMessage":"block not found: %s","messagePattern":"block not found: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/cli/cmd/block.go","lineNumber":384,"sourceCode":"\t\t\tmodel.AppendPushReloadProtyleEntry(rootID)\n\t\t}\n\t\tfmt.Println(\"ok\")\n\t\treturn nil\n\t},\n}\n\nvar blockDeleteCmd = &cobra.Command{\n\tUse:   \"delete --id <id>\",\n\tShort: \"Delete block\",\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\n\t\tbt := treenode.GetBlockTree(id)\n\t\tif bt == nil {\n\t\t\treturn fmt.Errorf(\"block not found: %s\", id)\n\t\t}\n\t\tif dryRun {\n\t\t\tfmt.Printf(\"[dry-run] Would delete block %s\\n\", id)\n\t\t\treturn nil\n\t\t}\n\n\t\ttransactions := []*model.Transaction{{\n\t\t\tDoOperations: []*model.Operation{{\n\t\t\t\tAction: \"delete\",\n\t\t\t\tID:     id,\n\t\t\t}},\n\t\t}}\n\t\tmodel.PerformTransactions(&transactions)\n\t\tmodel.FlushTxQueue()\n\n\t\tif bt != nil {\n\t\t\tmodel.AppendPushReloadProtyleEntry(bt.RootID)\n\t\t}","sourceCodeStart":366,"sourceCodeEnd":402,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/cli/cmd/block.go#L366-L402","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Verify the block ID exists (block info --id <id> or check the .sy file content).","Re-list blocks to refresh IDs if the notebook was reindexed or synced since capture.","Confirm the CLI runs against the intended workspace so GetBlockTree loads the right data.","Handle already-deleted IDs idempotently in scripts (ignore block-not-found)."],"exampleFix":"// before\nsiyuan block delete --id 20240101120000-olddoc1\n// error: block not found: 20240101120000-olddoc1\n// after\nsiyuan block info --id 20240101120000-olddoc1 || echo \"already gone; skipping\"\nsiyuan block delete --id 20240101120000-olddoc1","handlingStrategy":"try-catch","validationCode":"siyuan block info --id \"$BLOCK_ID\" >/dev/null 2>&1 || { echo \"block $BLOCK_ID does not exist; skipping\" >&2; exit 0; }","typeGuard":null,"tryCatchPattern":"if ! siyuan block delete --id \"$BLOCK_ID\"; then\n  case \"${BLOCK_ID}\" in *) echo \"delete failed; check block exists\" >&2;; esac\nfi","preventionTips":["Confirm the block exists before deleting (block info)","Refresh IDs after reindex or sync","Ensure the CLI targets the correct workspace"],"tags":["cli","not-found","block"],"backgroundTag":"entity-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"}