siyuan-note/siyuan · error

--ids is required

Error message

--ids is required

What it means

The `block batch-get` CLI command requires a comma-separated list of block IDs via the --ids flag. If the flag is absent or empty, RunE returns this error before doing any work (kernel/cli/cmd/block.go:481).

Solutions

  1. Add the --ids flag with comma-separated block IDs, e.g. --ids 20240101120000-abc,20240101120000-def
  2. If IDs come from a shell variable, verify it is non-empty before invoking the command
  3. Check flag spelling (--ids, not --id or --block-ids)

Example fix

// before
siyuan block batch-get
// after
siyuan block batch-get --ids 20240101120000-abc,20240101120000-def
Defensive patterns

Strategy: validation

Validate before calling

if [ -z "$IDS" ]; then echo "--ids is required" >&2; exit 1; fi
siyuan block batch-get --ids "$IDS"

Prevention

When it happens

Trigger: Running `siyuan block batch-get` without --ids, with `--ids ""`, or with the flag name misspelled so GetString returns the empty default.

Common situations: Copy-pasting example commands and dropping the flag; shell variable expansion producing an empty string (`--ids "$IDS"` with unset IDS); assuming positional arguments work instead of the flag.

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


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/9ed5148b28c681f2. Report an issue: GitHub.

Appendix: source

Thrown at kernel/cli/cmd/block.go:481

		}
		if "d" == previousBt.Type {
			return fmt.Errorf("document block [%s] cannot be used as a previous sibling; use it as --parent instead", previousID)
		}
		return nil
	}
	if err := treenode.CheckListItemNesting(parentID, id); err != nil {
		return err
	}
	return treenode.CheckContainerParent(parentID)
}

var blockBatchGetCmd = &cobra.Command{
	Use:   "batch-get --ids id1,id2,...",
	Short: "Batch get block info",
	RunE: func(cmd *cobra.Command, args []string) error {
		idsStr, _ := cmd.Flags().GetString("ids")
		if idsStr == "" {
			return fmt.Errorf("--ids is required")
		}
		ids := splitIDs(idsStr)
		if len(ids) == 0 {
			return fmt.Errorf("no valid IDs provided")
		}
		infos := model.GetDocsInfo(ids, false, false)
		switch outputFormat {
		case "json":
			data, _ := json.MarshalIndent(infos, "", "  ")
			fmt.Println(string(data))
		default:
			w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
			fmt.Fprintln(w, "ID\tNAME\tROOTID\tREFCOUNT")
			for _, info := range infos {
				fmt.Fprintf(w, "%s\t%s\t%s\t%d\n", info.ID, info.Name, info.RootID, info.RefCount)
			}
			for _, id := range ids {
				found := false

View on GitHub (pinned to 9f775e8a12)