{"record":{"id":"c5f724d55db2956d","repo":"siyuan-note/siyuan","slug":"previous-block-not-found-s","errorCode":null,"errorMessage":"previous block not found: %s","messagePattern":"previous block not found: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/cli/cmd/block.go","lineNumber":462,"sourceCode":"\t\t}\n\t\tfmt.Println(\"ok\")\n\t\treturn nil\n\t},\n}\n\nfunc validateBlockMove(id, parentID, previousID string) error {\n\tbt := treenode.GetBlockTree(id)\n\tif nil == bt {\n\t\treturn fmt.Errorf(\"block not found: %s\", id)\n\t}\n\tif \"d\" == bt.Type {\n\t\treturn fmt.Errorf(\"document block [%s] cannot be moved with block move; use document move instead\", id)\n\t}\n\n\tif \"\" != previousID {\n\t\tpreviousBt := treenode.GetBlockTree(previousID)\n\t\tif nil == previousBt {\n\t\t\treturn fmt.Errorf(\"previous block not found: %s\", previousID)\n\t\t}\n\t\tif \"d\" == previousBt.Type {\n\t\t\treturn fmt.Errorf(\"document block [%s] cannot be used as a previous sibling; use it as --parent instead\", previousID)\n\t\t}\n\t\treturn nil\n\t}\n\tif err := treenode.CheckListItemNesting(parentID, id); err != nil {\n\t\treturn err\n\t}\n\treturn treenode.CheckContainerParent(parentID)\n}\n\nvar blockBatchGetCmd = &cobra.Command{\n\tUse:   \"batch-get --ids id1,id2,...\",\n\tShort: \"Batch get block info\",\n\tRunE: func(cmd *cobra.Command, args []string) error {\n\t\tidsStr, _ := cmd.Flags().GetString(\"ids\")\n\t\tif idsStr == \"\" {","sourceCodeStart":444,"sourceCodeEnd":480,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/cli/cmd/block.go#L444-L480","documentation":"When moving a block with a --previousID (the sibling the moved block should follow), validateBlockMove looks up that sibling in the block tree. If no block tree node exists for it, this error is returned (kernel/cli/cmd/block.go:462), meaning the referenced previous-sibling block does not exist or is not indexed.","triggerScenarios":"Running a block move command with --previous <id> where the ID is mistyped, was deleted, points to a block in a closed/unloaded notebook, or points to an entity that was never a block (e.g. a notebook ID or asset path).","commonSituations":"Stale IDs cached from an earlier sync or export; typos when hand-writing CLI scripts; moving blocks after the previous sibling was removed by a concurrent edit; referencing a block in a notebook that is not currently open.","solutions":["Verify the previous-sibling ID exists via block info (CLI batch-get or /api/block/getBlockInfo) and correct typos","Re-list the sibling blocks of the target parent and use a current block ID as --previous","If the sibling no longer exists, use --parent with the containing parent ID instead of --previous","Ensure the notebook containing the sibling is open/synced so the block tree index contains it"],"exampleFix":"// before\nsiyuan block move --id 20240101120000-block1 --previous 20240101120000-deleted\n// after\nsiyuan block move --id 20240101120000-block1 --previous 20240101120000-currentsibling","handlingStrategy":"validation","validationCode":"if ! siyuan block batch-get --ids \"$PREVIOUS_ID\" >/dev/null 2>&1; then\n  echo \"previous sibling $PREVIOUS_ID does not exist\" >&2; exit 1\nfi","typeGuard":null,"tryCatchPattern":"err := validateBlockMove(id, parentID, previousID)\nif err != nil {\n    if strings.HasPrefix(err.Error(), \"previous block not found\") {\n        // fall back to parent-based placement\n    }\n    return err\n}","preventionTips":["Resolve previous-sibling IDs from a fresh block listing at run time, not cached values","Validate all IDs with batch-get before a batch move","Prefer --parent placement when sibling existence is uncertain"],"tags":["cli","block-move","not-found","stale-id"],"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"}