{"record":{"id":"0f03b6dac84b6eac","repo":"siyuan-note/siyuan","slug":"parent-is-required","errorCode":null,"errorMessage":"--parent is required","messagePattern":"--parent is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/cli/cmd/block.go","lineNumber":195,"sourceCode":"\t\t\tfmt.Printf(\"Blocks:     %d\\n\", stat.BlockCount)\n\t\t\tfmt.Printf(\"Links:      %d\\n\", stat.LinkCount)\n\t\t\tfmt.Printf(\"Images:     %d\\n\", stat.ImageCount)\n\t\t\tfmt.Printf(\"Refs:       %d\\n\", stat.RefCount)\n\t\t}\n\t\treturn nil\n\t},\n}\n\n// ─── Write ─────────────────────────────────────────────────────────────────────\n\nvar blockInsertCmd = &cobra.Command{\n\tUse:   \"insert --parent <id> [--data <markdown> | --file <path>]\",\n\tShort: \"Insert block\",\n\tRunE: func(cmd *cobra.Command, args []string) error {\n\t\tparentID, _ := cmd.Flags().GetString(\"parent\")\n\t\tpreviousID, _ := cmd.Flags().GetString(\"previous\")\n\t\tif parentID == \"\" {\n\t\t\treturn fmt.Errorf(\"--parent is required\")\n\t\t}\n\n\t\tif dryRun {\n\t\t\tfmt.Printf(\"[dry-run] Would insert block under parent %s\\n\", parentID)\n\t\t\tif previousID != \"\" {\n\t\t\t\tfmt.Printf(\"         after previous sibling %s\\n\", previousID)\n\t\t\t}\n\t\t\treturn nil\n\t\t}\n\n\t\t// 仅靠 parentID 定位目标时（无 previousID），目标必须是容器块，否则非法嵌套\n\t\tif previousID == \"\" {\n\t\t\tif err := treenode.CheckContainerParent(parentID); err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t}\n\n\t\tdata, err := resolveData(cmd)","sourceCodeStart":177,"sourceCodeEnd":213,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/251596fc0de2f9528c00c224252fd073a99973f4/kernel/cli/cmd/block.go#L177-L213","documentation":"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`.","triggerScenarios":"Running `siyuan-kernel block insert` without `--parent`. The command accepts `--parent` (required) plus optional `--previous` (sibling anchor) and `--data`/`--file` for content.","commonSituations":"Forgetting `--parent`; passing content via `--data` but omitting the target; confusing `--parent` with `--previous` (the sibling anchor).","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"],"exampleFix":"// before\nsiyuan-kernel block insert --data 'hello'\n// after\nsiyuan-kernel block insert --parent 20260605100657-v080a4j --data 'hello'","handlingStrategy":"validation","validationCode":"if strings.TrimSpace(parentID) == \"\" {\n    return fmt.Errorf(\"--parent is required for `block insert`\")\n}\nif !treenode.IsContainerType(getBlockType(parentID)) {\n    return fmt.Errorf(\"--parent must be a container block\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["cli","block","argument-validation","write","go"],"backgroundTag":null,"analyzedSha":"251596fc0de2f9528c00c224252fd073a99973f4","analyzedAt":"2026-08-12T21:18:37.123Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}