siyuan-note/siyuan · error

Field [groups] must not be empty

Error message

Field [groups] must not be empty

What it means

The groups array in /api/clipboard/cleanupRichText must contain at least one element. The groups identify which block groups to clean up; an empty array is rejected because the call would otherwise be a no-op.

Solutions

  1. Include at least one group identifier string in the groups array
  2. Skip the cleanup call entirely (client-side) when there are no groups to clean
  3. Verify the group-collection logic upstream so groups is populated before the request

Example fix

// before
fetchPost("/api/clipboard/cleanupRichText", {batch, groups: []})
// after
if (groups.length > 0) { fetchPost("/api/clipboard/cleanupRichText", {batch, groups}) }
Defensive patterns

Strategy: validation

Validate before calling

if (!Array.isArray(groups) || groups.length === 0) throw new Error('groups must be a non-empty array');

Prevention

When it happens

Trigger: POSTing {"batch":"...","groups":[]} to /api/clipboard/cleanupRichText, or a groups-building loop that collects nothing (e.g. no blocks matched the filter).

Common situations: Cleaning up after a copy where no groups were actually registered; filtering removed all group IDs before the call; assuming groups is optional and sending an empty array.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


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

Appendix: source

Thrown at kernel/apicontract/clipboard_input.go:63

		fields, err := blockRequestFields(reader, "/api/clipboard/cleanupRichText")
		if err != nil {
			return request, err
		}
		request.Batch, err = legacyField[string](fields, "batch", "String", true)
		if err != nil {
			return request, err
		}
		request.Batch = strings.TrimSpace(request.Batch)
		if request.Batch == "" {
			return request, fmt.Errorf("Field [batch] must not be empty")
		}
		groups, err := legacyField[[]json.RawMessage](fields, "groups", "Array", true)
		if err != nil {
			return request, err
		}
		request.Groups = make([]string, 0, len(groups))
		if len(groups) == 0 {
			return request, fmt.Errorf("Field [groups] must not be empty")
		}
		for i, raw := range groups {
			var group string
			if bytes.Equal(raw, []byte("null")) || json.Unmarshal(raw, &group) != nil {
				return request, fmt.Errorf("Field [groups.%d] should be of type [String]", i)
			}
			request.Groups = append(request.Groups, group)
		}
		return
	}
}

View on GitHub (pinned to 9f775e8a12)