{"record":{"id":"22f8a23584ef70ae","repo":"siyuan-note/siyuan","slug":"id-is-required-22f8a2","errorCode":null,"errorMessage":"--id is required","messagePattern":"--id is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/cli/cmd/export.go","lineNumber":40,"sourceCode":"\n\t\"github.com/siyuan-note/filelock\"\n\t\"github.com/siyuan-note/siyuan/kernel/model\"\n\n\t\"github.com/spf13/cobra\"\n)\n\nvar exportCmd = &cobra.Command{\n\tUse:   \"export\",\n\tShort: \"Export documents\",\n}\n\nvar exportMdCmd = &cobra.Command{\n\tUse:   \"md --id <id>\",\n\tShort: \"Export as Markdown\",\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\n\t\toutput, _ := cmd.Flags().GetString(\"output\")\n\t\tif dryRun {\n\t\t\tif output == \"\" {\n\t\t\t\toutput = \"stdout\"\n\t\t\t}\n\t\t\tfmt.Printf(\"[dry-run] Would export markdown for document %s to %s\\n\", id, output)\n\t\t\treturn nil\n\t\t}\n\n\t\t_, content := model.ExportMarkdownContent(id, 4, 0, true, false, false, false, false)\n\t\treturn writeExportContent(content, output)\n\t},\n}\n\nvar exportHTMLCmd = &cobra.Command{\n\tUse:   \"html --id <id>\",","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/cli/cmd/export.go#L22-L58","documentation":"The `siyuan export md` command requires `--id` naming the document to export as Markdown. The empty-flag guard runs first; only afterwards is `--output` read and the dry-run or actual export performed.","triggerScenarios":"Running `export md` without `--id`; `--id` sourced from an unset environment variable, empty CI input, or a failed upstream lookup; a wrapper dropping the flag when output is specified.","commonSituations":"Batch export scripts where the ID list contained an empty line; users specifying only --output assuming the current document is implied; docs examples copied incompletely.","solutions":["Run `siyuan export md --id <doc-id> [--output <path>]`","Validate the ID variable is non-empty before invoking the export","Obtain the ID with `siyuan document search` and skip empty entries in batch lists"],"exampleFix":"// before\ncat ids.txt | while read id; do export md --id \"$id\"; done   // blank line triggers error\n// after\ncat ids.txt | while read id; do [ -n \"$id\" ] && export md --id \"$id\"; done","handlingStrategy":"validation","validationCode":"if [ -z \"$DOC_ID\" ]; then echo \"--id is required for export md\" >&2; exit 2; fi\nsiyuan export md --id \"$DOC_ID\" --output \"$OUT\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Trim and drop empty lines when reading ID lists for batch exports","Always pair --output with a validated --id; never assume a current document","Dry-run first (the command supports it) to confirm the ID resolves before real exports"],"tags":["cli","validation","missing-flag","export"],"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"}