siyuan-note/siyuan · error

--ids is required

Error message

--ids is required

What it means

Thrown by the `attr batch-get` subcommand when `--ids` is empty. `--ids` is a single comma-separated string (not a StringArray) that gets split into a slice; an empty string means nothing to look up. The call into `sql.BatchGetBlockAttrs(ids)` is skipped.

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

Solutions

  1. Supply a comma-separated list: `siyuan-kernel attr batch-get --ids 20260605100657-v080a4j,20260605100658-abc1234`
  2. Remember `--ids` is a single string, not repeated like `--attr`
  3. Trim stray whitespace; each element is `strings.TrimSpace`-d but the whole string must be non-empty

Example fix

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

Strategy: validation

Validate before calling

// Build the comma-joined ids string defensively.
ids := []string{"20260605100657-v080a4j", "20260605100658-abc1234"}
cleaned := []string{}
for _, id := range ids {
    if t := strings.TrimSpace(id); t != "" {
        cleaned = append(cleaned, t)
    }
}
if len(cleaned) == 0 {
    return fmt.Errorf("no block IDs to query")
}
idsStr := strings.Join(cleaned, ",")

Prevention

When it happens

Trigger: Running `siyuan-kernel attr batch-get` with no `--ids`, or `--ids ""`. Only an empty string triggers it — whitespace-only values pass through and are trimmed per-element.

Common situations: Forgetting the flag; passing the IDs as positional args instead of via `--ids`; expecting `--ids` to be repeatable like `--attr` (it is not — it is one comma-joined string).

Related errors


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