siyuan-note/siyuan · error
--id is required
Error message
--id is required
What it means
The `siyuan document get` command requires the document (block) ID via `--id`. RunE rejects an empty id before calling treenode.GetBlockTree. This is a presence check only; a syntactically valid but unknown ID produces the separate "document not found" error instead.
Solutions
- Pass the document/block ID: `siyuan document get --id 20240101120000-abcdefgh`
- Get a valid ID from `siyuan document list --notebook <notebookID>` first
- Check the flag spelling and that the variable holding the ID is populated
Example fix
// before siyuan document get // after siyuan document get --id 20240101120000-abcdefgh
Defensive patterns
Strategy: validation
Validate before calling
[ -n "$DOC_ID" ] || { echo "--id is required" >&2; exit 1; }
siyuan document get --id "$DOC_ID" Prevention
- Substitute real IDs into copied usage examples, not the `<id>` placeholder
- Capture IDs from document list output into variables immediately
- Verify flag name spelling (--id, not --doc or --block)
When it happens
Trigger: Running `siyuan document get` without `--id <id>` or with an empty value. Unknown flag names (e.g. `--doc`) also yield "" and thus this error.
Common situations: Copy-pasting the usage line `get --id <id>` literally instead of substituting a real ID; scripts where the DOC_ID variable is empty because a previous list command output was not captured; flag typo.
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
- --notebook is required
- --title is required
- --av and --ids are required
- --av, --key, --item and --value are required
- --block is required for non-detached rows
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/113ed837ba4a7e92.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/cli/cmd/document.go:117
fmt.Println(id)
return nil
},
}
func normalizeDocumentCreateParentPath(parentPath string) string {
if "" == parentPath {
return "/"
}
return strings.TrimSuffix(path.Clean(parentPath), ".sy")
}
var documentGetCmd = &cobra.Command{
Use: "get --id <id>",
Short: "Get document info",
RunE: func(cmd *cobra.Command, args []string) error {
id, _ := cmd.Flags().GetString("id")
if id == "" {
return fmt.Errorf("--id is required")
}
bt := treenode.GetBlockTree(id)
if bt == nil {
return fmt.Errorf("document not found: %s", id)
}
tree, err := model.LoadTreeByBlockID(id)
if err != nil {
return err
}
block, err := model.GetBlock(id, tree)
if err != nil {
return err
}
switch outputFormat {
case "json":
data, _ := json.MarshalIndent(block, "", " ")View on GitHub (pinned to 9f775e8a12)