{"record":{"id":"113ed837ba4a7e92","repo":"siyuan-note/siyuan","slug":"id-is-required-113ed8","errorCode":null,"errorMessage":"--id is required","messagePattern":"--id is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/cli/cmd/document.go","lineNumber":113,"sourceCode":"\t\tfmt.Println(id)\n\t\treturn nil\n\t},\n}\n\nfunc normalizeDocumentCreateParentPath(parentPath string) string {\n\tif \"\" == parentPath {\n\t\treturn \"/\"\n\t}\n\treturn strings.TrimSuffix(path.Clean(parentPath), \".sy\")\n}\n\nvar documentGetCmd = &cobra.Command{\n\tUse:   \"get --id <id>\",\n\tShort: \"Get document 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\tbt := treenode.GetBlockTree(id)\n\t\tif bt == nil {\n\t\t\treturn fmt.Errorf(\"document not found: %s\", id)\n\t\t}\n\n\t\ttree, err := model.LoadTreeByBlockID(id)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tblock, err := model.GetBlock(id, tree)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\tswitch outputFormat {\n\t\tcase \"json\":\n\t\t\tdata, _ := json.MarshalIndent(block, \"\", \"  \")","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/251596fc0de2f9528c00c224252fd073a99973f4/kernel/cli/cmd/document.go#L95-L131","documentation":"The `document get` cobra subcommand requires the --id flag pointing to a block ID. The handler reads --id and returns this error when empty, before calling treenode.GetBlockTree. The ID must be a valid SiYuan block ID (typically a 14-digit timestamp + random suffix, e.g. 20240101000000-abc1234) that identifies a document root or child block.","triggerScenarios":"Running `siyuan document get` with no flags; passing `--id \"\"`; misspelling the flag; copying a truncated ID from a URL; scripting with an unset ID variable.","commonSituations":"Forgetting the ID after switching context; assuming positional ID argument support; passing the document title instead of its ID; referencing a shell variable that was never populated; trailing whitespace in the ID.","solutions":["Supply the document/block ID: `siyuan document get --id 20240101000000-abc1234`.","Obtain the ID via `siyuan document list --notebook <id>` or `siyuan document search <keyword>`.","Trim whitespace in scripts: `--id \"$(echo $id | tr -d '[:space:]')\".","Verify the flag name with `siyuan document get --help`."],"exampleFix":"// before\nsiyuan document get\n// after\nsiyuan document get --id 20240101000000-abc1234","handlingStrategy":"validation","validationCode":"[ -n \"$DOC_ID\" ] || { echo '--id is required' >&2; exit 2; }\nsiyuan document get --id \"$DOC_ID\"","typeGuard":"// Go: SiYuan block IDs match this shape\nvar blockIDRe = regexp.MustCompile(`^\\d{14}-[a-z0-9]+$`)\nfunc isValidBlockID(id string) bool { return blockIDRe.MatchString(id) }","tryCatchPattern":"if ! siyuan document get --id \"$DOC_ID\" 2>err.txt; then\n  grep -qE 'id is required|not found' err.txt && echo \"check --id (try: siyuan document search <keyword>)\" >&2\n  exit 1\nfi","preventionTips":["Trim whitespace/newlines from copied IDs.","Keep a lookup step (list/search) before get in scripts.","Validate the ID shape with a regex before invoking."],"tags":["cli","cobra","flag-validation","document","block-id","go"],"backgroundTag":null,"analyzedSha":"251596fc0de2f9528c00c224252fd073a99973f4","analyzedAt":"2026-08-12T21:18:37.123Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}