{"record":{"id":"502e1bcc94c2390d","repo":"siyuan-note/siyuan","slug":"id-is-required-502e1b","errorCode":null,"errorMessage":"--id is required","messagePattern":"--id is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/cli/cmd/block.go","lineNumber":48,"sourceCode":"\t\"github.com/siyuan-note/siyuan/kernel/util\"\n\n\t\"github.com/spf13/cobra\"\n)\n\nvar blockCmd = &cobra.Command{\n\tUse:   \"block\",\n\tShort: \"Block operations\",\n}\n\n// ─── Read ──────────────────────────────────────────────────────────────────────\n\nvar blockGetCmd = &cobra.Command{\n\tUse:   \"get --id <id>\",\n\tShort: \"Get block info\",\n\tRunE: func(cmd *cobra.Command, args []string) error {\n\t\tid, _ := cmd.Flags().GetString(\"id\")\n\t\tif id == \"\" {\n\t\t\treturn fmt.Errorf(\"--id is required\")\n\t\t}\n\t\tblock, err := model.GetBlock(id, nil)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tswitch outputFormat {\n\t\tcase \"json\":\n\t\t\tdata, _ := json.MarshalIndent(block, \"\", \"  \")\n\t\t\tfmt.Println(string(data))\n\t\tdefault:\n\t\t\tfmt.Printf(\"ID:       %s\\n\", block.ID)\n\t\t\tfmt.Printf(\"Type:     %s\\n\", block.Type)\n\t\t\tfmt.Printf(\"Name:     %s\\n\", block.Name)\n\t\t\tfmt.Printf(\"Box:      %s\\n\", block.Box)\n\t\t\tfmt.Printf(\"HPath:    %s\\n\", block.HPath)\n\t\t\tif block.Content != \"\" {\n\t\t\t\tfmt.Printf(\"Content:  %s\\n\", truncate(block.Content, 200))\n\t\t\t}","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/cli/cmd/block.go#L30-L66","documentation":"`siyuan-kernel block get` fetches a block's info by id and requires the `--id` flag. The RunE handler returns this error when the flag is missing or empty, before calling model.GetBlock. Note the error is about argument presence, not block existence — an unknown but supplied id yields a different error.","triggerScenarios":"`siyuan-kernel block get` with no --id flag, or `--id ''`.","commonSituations":"Copy-paste dropping the long 21-character block id; shell variable empty because the block-id extraction step failed; mixing up which subcommands use --id vs --ids.","solutions":["Supply the id: `siyuan-kernel block get --id 20260605100657-v080a4j`","Copy the block id from the SiYuan UI and confirm it is non-empty","Guard scripts: `[ -n \"$ID\" ] || exit 1` before calling the command"],"exampleFix":"// before\nsiyuan-kernel block get\n// after\nsiyuan-kernel block get --id 20260605100657-v080a4j","handlingStrategy":"validation","validationCode":"if [ -z \"$ID\" ]; then echo \"--id is required\" >&2; exit 1; fi\nsiyuan-kernel block get --id \"$ID\"","typeGuard":"function hasBlockId(args) { return typeof args.id === \"string\" && args.id.length > 0; }","tryCatchPattern":"if err := cmd.Execute(); err != nil && strings.Contains(err.Error(), \"--id is required\") { // print usage }","preventionTips":["Keep block ids in one validated variable per script","Remember --id presence is checked first; a wrong-but-present id gives a different (not-found) error","Use the same guard function across all block subcommands"],"tags":["cli","required-flag","argument-validation"],"backgroundTag":"missing-required-flag","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"}