siyuan-note/siyuan · error
previous block not found
Error message
previous block not found: %s
What it means
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.
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
Example fix
// before siyuan block move --id 20240101120000-block1 --previous 20240101120000-deleted // after siyuan block move --id 20240101120000-block1 --previous 20240101120000-currentsibling
Defensive patterns
Strategy: validation
Validate before calling
if ! siyuan block batch-get --ids "$PREVIOUS_ID" >/dev/null 2>&1; then echo "previous sibling $PREVIOUS_ID does not exist" >&2; exit 1 fi
Try / catch
err := validateBlockMove(id, parentID, previousID)
if err != nil {
if strings.HasPrefix(err.Error(), "previous block not found") {
// fall back to parent-based placement
}
return err
} Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- block not found
- database not found
- document block [ ] cannot be moved with block move; use…
- document block [ ] cannot be used as a previous sibling…
- document not found or empty
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/c5f724d55db2956d.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/cli/cmd/block.go:462
}
fmt.Println("ok")
return nil
},
}
func validateBlockMove(id, parentID, previousID string) error {
bt := treenode.GetBlockTree(id)
if nil == bt {
return fmt.Errorf("block not found: %s", id)
}
if "d" == bt.Type {
return fmt.Errorf("document block [%s] cannot be moved with block move; use document move instead", id)
}
if "" != previousID {
previousBt := treenode.GetBlockTree(previousID)
if nil == previousBt {
return fmt.Errorf("previous block not found: %s", previousID)
}
if "d" == previousBt.Type {
return fmt.Errorf("document block [%s] cannot be used as a previous sibling; use it as --parent instead", previousID)
}
return nil
}
if err := treenode.CheckListItemNesting(parentID, id); err != nil {
return err
}
return treenode.CheckContainerParent(parentID)
}
var blockBatchGetCmd = &cobra.Command{
Use: "batch-get --ids id1,id2,...",
Short: "Batch get block info",
RunE: func(cmd *cobra.Command, args []string) error {
idsStr, _ := cmd.Flags().GetString("ids")
if idsStr == "" {View on GitHub (pinned to 9f775e8a12)