{"record":{"id":"316897b5b8a9804f","repo":"siyuan-note/siyuan","slug":"output-is-required-for-docx","errorCode":null,"errorMessage":"--output is required for docx","messagePattern":"--output is required for docx","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/cli/cmd/export.go","lineNumber":113,"sourceCode":"\t\t\treturn nil\n\t\t}\n\n\t\thtml := model.ExportPreview(id, false)\n\t\treturn writeExportContent(html, output)\n\t},\n}\n\nvar exportDocxCmd = &cobra.Command{\n\tUse:   \"docx --id <id> --output <file>\",\n\tShort: \"Export as Word (.docx)\",\n\tRunE: func(cmd *cobra.Command, args []string) error {\n\t\tid, _ := cmd.Flags().GetString(\"id\")\n\t\toutput, _ := cmd.Flags().GetString(\"output\")\n\t\tif id == \"\" {\n\t\t\treturn fmt.Errorf(\"--id is required\")\n\t\t}\n\t\tif output == \"\" {\n\t\t\treturn fmt.Errorf(\"--output is required for docx\")\n\t\t}\n\n\t\tif dryRun {\n\t\t\tfmt.Printf(\"[dry-run] Would export docx for document %s to %s\\n\", id, output)\n\t\t\treturn nil\n\t\t}\n\n\t\tfullPath, err := model.ExportDocx(id, output, false, false)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tfmt.Println(fullPath)\n\t\treturn nil\n\t},\n}\n\nvar exportSYCmd = &cobra.Command{\n\tUse:   \"sy --id <id> [--output <file>]\",","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/cli/cmd/export.go#L95-L131","documentation":"The `siyuan export docx` subcommand requires an output file path via `--output` because a .docx is a binary artifact that cannot be streamed to stdout. The handler returns this error when the flag is empty or absent, after the `--id` check passes.","triggerScenarios":"Running `siyuan export docx --id <id>` with no `--output`, or `--output \"\"`.","commonSituations":"Reusing an invocation pattern from the html/preview/sy/md-zip subcommands where `--output` is optional (stdout fallback); scripts that omit the flag for dry-run mode.","solutions":["Re-run with an explicit destination: `siyuan export docx --id <id> --output /path/to/file.docx`.","Ensure the parent directory of the output path exists and is writable.","Remember docx never prints to stdout, unlike html/preview.","Use --dry-run first to preview the planned export without writing."],"exampleFix":"// before\nsiyuan export docx --id 20240101120000-abc1234\n\n// after\nsiyuan export docx --id 20240101120000-abc1234 --output ./report.docx","handlingStrategy":"validation","validationCode":"if [ -z \"$OUT\" ]; then echo \"error: --output is required for docx\" >&2; exit 1; fi\nmkdir -p \"$(dirname \"$OUT\")\"","typeGuard":null,"tryCatchPattern":"siyuan export docx --id \"$DOC_ID\" --output \"$OUT\" || { echo 'docx export failed (is --output set?)' >&2; exit 1; }","preventionTips":["Never assume stdout fallback for binary formats like docx","Create the output directory before exporting","Only html/preview (and optionally sy/md-zip) can fall back to stdout","Use --dry-run to echo the planned output path"],"tags":["cli","missing-argument","export","docx"],"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"}