{"record":{"id":"c3ab4886971fcace","repo":"siyuan-note/siyuan","slug":"id-is-required-c3ab48","errorCode":null,"errorMessage":"--id is required","messagePattern":"--id is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/cli/cmd/outline.go","lineNumber":40,"sourceCode":"\t\"strings\"\n\n\t\"github.com/siyuan-note/siyuan/kernel/model\"\n\n\t\"github.com/spf13/cobra\"\n)\n\nvar outlineCmd = &cobra.Command{\n\tUse:   \"outline\",\n\tShort: \"Document outline (heading tree)\",\n}\n\nvar outlineGetCmd = &cobra.Command{\n\tUse:   \"get --id <id>\",\n\tShort: \"Get document outline\",\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\tpaths, err := model.Outline(id, false)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tif len(paths) == 0 {\n\t\t\treturn fmt.Errorf(\"document not found or has no headings\")\n\t\t}\n\t\tswitch outputFormat {\n\t\tcase \"json\":\n\t\t\tdata, _ := json.MarshalIndent(paths, \"\", \"  \")\n\t\t\tfmt.Println(string(data))\n\t\tdefault:\n\t\t\tvar sb strings.Builder\n\t\t\tsb.WriteString(fmt.Sprintf(\"Document outline (%d headings):\\n\\n\", countOutlineHeadings(paths)))\n\t\t\tfor _, p := range paths {\n\t\t\t\twriteOutlinePath(&sb, p, 0)\n\t\t\t}","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/cli/cmd/outline.go#L22-L58","documentation":"Argument validation in the cobra outlineGet RunE: fires when the --id flag is empty. Fetching a document outline requires the document (root block) ID to pass to model.Outline; running `outline get` without --id is the faulting usage.","triggerScenarios":"Running `outline get` without `--id` or with an empty value.","commonSituations":"Forgetting to substitute the doc id in scripts; empty shell variable from a failed lookup.","solutions":["Re-run with `--id <document-id>`","Get the document id from the SiYuan UI (copy block id) or a query command","Validate the variable is non-empty before invoking"],"exampleFix":"// before\nsiyuan outline get\n// after\nsiyuan outline get --id 20240101120000-abcdefg","handlingStrategy":"validation","validationCode":"[ -n \"$DOC_ID\" ] || { echo \"--id is required\"; exit 1; }\nsiyuan outline get --id \"$DOC_ID\"","typeGuard":"const isNonEmptyString = (v) => typeof v === \"string\" && v.length > 0;","tryCatchPattern":"try { run(`siyuan outline get --id ${docId}`); } catch (e) { console.error(e.message); }","preventionTips":["Capture document ids from the editor before scripting","Fail fast on empty variables in shell scripts","Use kramdown block-id syntax to pin stable ids in documents"],"tags":["cli","flag-validation","outline"],"backgroundTag":"missing-cli-argument","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"}