siyuan-note/siyuan · error
--id is required
Error message
--id is required
What it means
`siyuan-kernel block get` fetches a block's info by id and requires the `--id` flag. The RunE handler returns this error when the flag is missing or empty, before calling model.GetBlock. Note the error is about argument presence, not block existence — an unknown but supplied id yields a different error.
Solutions
- Supply the id: `siyuan-kernel block get --id 20260605100657-v080a4j`
- Copy the block id from the SiYuan UI and confirm it is non-empty
- Guard scripts: `[ -n "$ID" ] || exit 1` before calling the command
Example fix
// before siyuan-kernel block get // after siyuan-kernel block get --id 20260605100657-v080a4j
Defensive patterns
Strategy: validation
Validate before calling
if [ -z "$ID" ]; then echo "--id is required" >&2; exit 1; fi siyuan-kernel block get --id "$ID"
Type guard
function hasBlockId(args) { return typeof args.id === "string" && args.id.length > 0; } Try / catch
if err := cmd.Execute(); err != nil && strings.Contains(err.Error(), "--id is required") { // print usage } Prevention
- Keep block ids in one validated variable per script
- Remember --id presence is checked first; a wrong-but-present id gives a different (not-found) error
- Use the same guard function across all block subcommands
When it happens
Trigger: `siyuan-kernel block get` with no --id flag, or `--id ''`.
Common situations: Copy-paste dropping the long 21-character block id; shell variable empty because the block-id extraction step failed; mixing up which subcommands use --id vs --ids.
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
- --attr is required (format: name=value)
- --ids is required
- --remote requires a URL
- appearance files not found at
- --av and --ids are required
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/502e1bcc94c2390d.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/cli/cmd/block.go:48
"github.com/siyuan-note/siyuan/kernel/util"
"github.com/spf13/cobra"
)
var blockCmd = &cobra.Command{
Use: "block",
Short: "Block operations",
}
// ─── Read ──────────────────────────────────────────────────────────────────────
var blockGetCmd = &cobra.Command{
Use: "get --id <id>",
Short: "Get block info",
RunE: func(cmd *cobra.Command, args []string) error {
id, _ := cmd.Flags().GetString("id")
if id == "" {
return fmt.Errorf("--id is required")
}
block, err := model.GetBlock(id, nil)
if err != nil {
return err
}
switch outputFormat {
case "json":
data, _ := json.MarshalIndent(block, "", " ")
fmt.Println(string(data))
default:
fmt.Printf("ID: %s\n", block.ID)
fmt.Printf("Type: %s\n", block.Type)
fmt.Printf("Name: %s\n", block.Name)
fmt.Printf("Box: %s\n", block.Box)
fmt.Printf("HPath: %s\n", block.HPath)
if block.Content != "" {
fmt.Printf("Content: %s\n", truncate(block.Content, 200))
}View on GitHub (pinned to 9f775e8a12)