siyuan-note/siyuan · error
--parent is required
Error message
--parent is required
What it means
Argument validation in the cobra blockInsert RunE: fires when the --parent flag is empty. Inserting a block requires a parent block ID to position the new content (with --previous or as last child); running `block insert` without --parent is the faulting usage.
Solutions
- Add --parent <blockID> specifying the block under which to insert.
- Ensure the variable feeding --parent is non-empty before invoking (e.g. `${PARENT_ID:?parent required}`).
- Use --file or --data to supply content once --parent is set.
Example fix
// before siyuan block insert --data "new text" // after siyuan block insert --parent 20240101120000-h1x2y3z --data "new text"
Defensive patterns
Strategy: validation
Validate before calling
: "${PARENT_ID:?--parent is required}"
siyuan block insert --parent "$PARENT_ID" --data "$DATA" Try / catch
siyuan block insert --parent "$PARENT_ID" --data "$DATA" || exit $?
Prevention
- Always pass --parent explicitly in scripts
- Fail fast on empty variables with ${VAR:?msg}
- Remember --previous is optional, --parent is not
When it happens
Trigger: Running `siyuan block insert` without --parent, or with `--parent ""` (empty value).
Common situations: Forgetting the flag when scripting; shell variable holding the parent ID is unset/empty; confusing --parent with --previous and omitting the required one.
Understand the failure class
Background: "--flag is required" and "must specify" CLI errors: how missing-required-flag validation works and how to fix it — this error's family across 20 libraries.
Related errors
- --id and --parent are required
- --av and --ids are required
- --av and --key are required
- --av is required
- --av, --key, --item and --value are required
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/0f03b6dac84b6eac.
Report an issue: GitHub.
Appendix: 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 9f775e8a12)