siyuan-note/siyuan · error
--parent is required
Error message
--parent is required
What it means
Thrown by the `block insert` subcommand when `--parent` is empty. `--parent` locates the container that will hold the new block. Without it the transaction target is undefined; the guard fires before dry-run and before `CheckContainerParent`.
Source
Thrown at kernel/cli/cmd/block.go:195
fmt.Printf("Blocks: %d\n", stat.BlockCount)
fmt.Printf("Links: %d\n", stat.LinkCount)
fmt.Printf("Images: %d\n", stat.ImageCount)
fmt.Printf("Refs: %d\n", stat.RefCount)
}
return nil
},
}
// ─── Write ─────────────────────────────────────────────────────────────────────
var blockInsertCmd = &cobra.Command{
Use: "insert --parent <id> [--data <markdown> | --file <path>]",
Short: "Insert block",
RunE: func(cmd *cobra.Command, args []string) error {
parentID, _ := cmd.Flags().GetString("parent")
previousID, _ := cmd.Flags().GetString("previous")
if parentID == "" {
return fmt.Errorf("--parent is required")
}
if dryRun {
fmt.Printf("[dry-run] Would insert block under parent %s\n", parentID)
if previousID != "" {
fmt.Printf(" after previous sibling %s\n", previousID)
}
return nil
}
// 仅靠 parentID 定位目标时(无 previousID),目标必须是容器块,否则非法嵌套
if previousID == "" {
if err := treenode.CheckContainerParent(parentID); err != nil {
return err
}
}
data, err := resolveData(cmd)View on GitHub (pinned to 251596fc0d)
Solutions
- Supply a container block ID: `siyuan-kernel block insert --parent 20260605100657-v080a4j --data 'new text'`
- Ensure `--parent` is a container block (d/b/l/i/s/callout); leaf types are rejected later by `CheckContainerParent`
- Use `--previous <siblingID>` to insert after a specific sibling instead of relying on parent-only placement
Example fix
// before siyuan-kernel block insert --data 'hello' // after siyuan-kernel block insert --parent 20260605100657-v080a4j --data 'hello'
Defensive patterns
Strategy: validation
Validate before calling
if strings.TrimSpace(parentID) == "" {
return fmt.Errorf("--parent is required for `block insert`")
}
if !treenode.IsContainerType(getBlockType(parentID)) {
return fmt.Errorf("--parent must be a container block")
} Prevention
- Validate `--parent` is a container type BEFORE inserting to avoid the downstream CheckContainerParent error
- Provide `--previous` when inserting below a heading (headings are leaf blocks)
- Use `--dry-run` to validate structure without writing
When it happens
Trigger: Running `siyuan-kernel block insert` without `--parent`. The command accepts `--parent` (required) plus optional `--previous` (sibling anchor) and `--data`/`--file` for content.
Common situations: Forgetting `--parent`; passing content via `--data` but omitting the target; confusing `--parent` with `--previous` (the sibling anchor).
Related errors
- --id and --parent are required
- --id is required
- --attr is required (format: name=value)
- --ids is required
- document not found or empty
AI-assisted analysis of siyuan-note/siyuan@251596fc0d (2026-08-12).
Data as JSON: /api/errors/0f03b6dac84b6eac.
Report an issue: GitHub.