siyuan-note/siyuan · error
--id is required
Error message
--id is required
What it means
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.
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
Example fix
// before cat ids.txt | while read id; do export md --id "$id"; done // blank line triggers error // after cat ids.txt | while read id; do [ -n "$id" ] && export md --id "$id"; done
Defensive patterns
Strategy: validation
Validate before calling
if [ -z "$DOC_ID" ]; then echo "--id is required for export md" >&2; exit 2; fi siyuan export md --id "$DOC_ID" --output "$OUT"
Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "--flag is required" and "must specify" CLI errors: how missing-required-flag validation works and how to fix it — this error's family across 20 libraries.
Related errors
- --av and --ids are required
- --av, --key, --item and --value are required
- --block is required for non-detached rows
- --id and --notebook are required
- --id is required
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/22f8a23584ef70ae.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/cli/cmd/export.go:40
"github.com/siyuan-note/filelock"
"github.com/siyuan-note/siyuan/kernel/model"
"github.com/spf13/cobra"
)
var exportCmd = &cobra.Command{
Use: "export",
Short: "Export documents",
}
var exportMdCmd = &cobra.Command{
Use: "md --id <id>",
Short: "Export as Markdown",
RunE: func(cmd *cobra.Command, args []string) error {
id, _ := cmd.Flags().GetString("id")
if id == "" {
return fmt.Errorf("--id is required")
}
output, _ := cmd.Flags().GetString("output")
if dryRun {
if output == "" {
output = "stdout"
}
fmt.Printf("[dry-run] Would export markdown for document %s to %s\n", id, output)
return nil
}
_, content := model.ExportMarkdownContent(id, 4, 0, true, false, false, false, false)
return writeExportContent(content, output)
},
}
var exportHTMLCmd = &cobra.Command{
Use: "html --id <id>",View on GitHub (pinned to 9f775e8a12)