siyuan-note/siyuan · error

--ids is required

Error message

--ids is required

What it means

The `attr batch-get` subcommand reads attributes for multiple blocks from a single comma-separated `--ids` flag. If the flag is absent or empty, the handler returns this error before splitting the list. It is a plain required-flag guard.

Solutions

  1. Pass the ids flag: `siyuan-kernel attr batch-get --ids id1,id2`
  2. Note the flag is plural `--ids` (this subcommand) versus `--id` used by get/children/dom etc.
  3. In scripts, abort when the computed id list is empty instead of invoking the command

Example fix

// before
siyuan-kernel attr batch-get --id 20260605100657-v080a4j
// after
siyuan-kernel attr batch-get --ids 20260605100657-v080a4j,20260605100658-x1b2c3d
Defensive patterns

Strategy: validation

Validate before calling

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

Type guard

function hasIdList(args) { return typeof args.ids === "string" && args.ids.trim().length > 0; }

Try / catch

if err := cmd.Execute(); err != nil && strings.Contains(err.Error(), "--ids is required") { // cmd.Usage() }

Prevention

When it happens

Trigger: `siyuan-kernel attr batch-get` with no flags; `--ids ''` after a variable expansion produced nothing; using positional arguments instead of --ids.

Common situations: Scripting a batch lookup where the id list variable is empty because an upstream query returned nothing; mistyping the flag as --id (singular, as used by other subcommands).

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/295c283e8775c6ee. Report an issue: GitHub.

Appendix: source

Thrown at kernel/cli/cmd/attr.go:118

			return nil
		}

		if err := model.SetBlockAttrs(id, nameValues); err != nil {
			return err
		}
		model.AppendPushReloadFiletreeEntry()
		fmt.Println("ok")
		return nil
	},
}

var attrBatchGetCmd = &cobra.Command{
	Use:   "batch-get --ids id1,id2,...",
	Short: "Batch get block attributes",
	RunE: func(cmd *cobra.Command, args []string) error {
		idsStr, _ := cmd.Flags().GetString("ids")
		if idsStr == "" {
			return fmt.Errorf("--ids is required")
		}

		ids := strings.Split(idsStr, ",")
		for i := range ids {
			ids[i] = strings.TrimSpace(ids[i])
		}

		attrs := sql.BatchGetBlockAttrs(ids)
		switch outputFormat {
		case "json":
			data, _ := json.MarshalIndent(attrs, "", "  ")
			fmt.Println(string(data))
		default:
			for id, a := range attrs {
				fmt.Printf("\n[%s]\n", id)
				printAttrTable(a)
			}
		}

View on GitHub (pinned to 9f775e8a12)