siyuan-note/siyuan · error

--id is required

Error message

--id is required

What it means

Thrown by the `block get` subcommand when `--id` is empty. `--id` selects the block to read via `model.GetBlock(id, nil)`. Without it there is no target; the command aborts before touching the model layer.

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 251596fc0d)

Solutions

  1. Pass a valid block ID: `siyuan-kernel block get --id 20260605100657-v080a4j`
  2. Get the ID from `siyuan-kernel sql` or the editor's block menu first if unknown
  3. Check that the ID was not mangled by shell expansion (IDs contain hyphens)

Example fix

// before
siyuan-kernel block get
// after
siyuan-kernel block get --id 20260605100657-v080a4j
Defensive patterns

Strategy: validation

Validate before calling

if strings.TrimSpace(blockID) == "" {
    return fmt.Errorf("block ID is required for `block get`")
}
// then: siyuan-kernel block get --id <blockID>

Prevention

When it happens

Trigger: Running `siyuan-kernel block get` without `--id`, or with `--id ""`. The block ID is the SiYuan document/block identifier (format like `20260605100657-v080a4j`).

Common situations: Forgetting the flag; passing a positional ID instead of `--id`; copy-paste leaving the placeholder `<id>` empty.

Related errors


AI-assisted analysis of siyuan-note/siyuan@251596fc0d (2026-08-12). Data as JSON: /api/errors/502e1bcc94c2390d. Report an issue: GitHub.