siyuan-note/siyuan · warning

invalid card size preset [%v]

Error message

invalid card size preset [%v]

What it means

Returned by setAttrViewCardSize (attribute_view.go:1652), dispatched through the transaction action "setAttrViewCardSize". operation.Data must be a float64 (else error 437), a whole number (value == math.Trunc(value)), and av.CardSize(value) within [CardSizeSmall=0 .. CardSizeLarge=2]. The valid presets are 0 (small), 1 (medium), 2 (large); CardWidthBySize derives the pixel width from this enum.

Source

Thrown at kernel/model/attribute_view.go:1652

	return
}

func (tx *Transaction) doSetAttrViewCardSize(operation *Operation) (ret *TxErr) {
	err := setAttrViewCardSize(operation)
	if err != nil {
		return &TxErr{code: TxErrHandleAttributeView, id: operation.AvID, msg: err.Error()}
	}
	return
}

func setAttrViewCardSize(operation *Operation) (err error) {
	value, err := getAttrViewOperationNumber(operation)
	if nil != err {
		return
	}
	size := av.CardSize(value)
	if value != math.Trunc(value) || size < av.CardSizeSmall || av.CardSizeLarge < size {
		return fmt.Errorf("invalid card size preset [%v]", value)
	}

	attrView, err := av.ParseAttributeView(operation.AvID)
	if err != nil {
		return
	}

	view, err := getAttrViewViewByBlockID(attrView, operation.BlockID)
	if err != nil {
		return
	}

	switch view.LayoutType {
	case av.LayoutTypeTable:
		return
	case av.LayoutTypeGallery:
		view.Gallery.CardSize = size
		view.Gallery.CardWidth = av.CardWidthBySize(size)

View on GitHub (pinned to 251596fc0d)

Solutions

  1. Send only 0, 1, or 2 (small / medium / large) as an integer JSON number.
  2. If you need an exact pixel width, use the separate action setAttrViewCardWidth (error 433) which accepts 140–600.
  3. Keep the preset index and the derived width in sync via av.CardWidthBySize on the client.

Example fix

// before: sending a pixel value as the preset
transaction({ op: "setAttrViewCardSize", data: 260 })

// after: send the preset index (1 = medium, derives width 260)
transaction({ op: "setAttrViewCardSize", data: 1 })
Defensive patterns

Strategy: validation

Validate before calling

// Card size is an enum index, not pixels: only 0,1,2 are valid.
if (![0,1,2].includes(data) || !Number.isInteger(data)) {
  throw new Error('card size preset must be 0, 1, or 2')
}

Type guard

function isCardSizePreset(v: unknown): v is number {
  return typeof v === 'number' && Number.isInteger(v) && v >= 0 && v <= 2
}

Prevention

When it happens

Trigger: Frontend sends setAttrViewCardSize with a non-integer (e.g. 1.5) or an integer outside 0–2 (e.g. 3 or -1). The value is an enum index, not a pixel size.

Common situations: Plugin sends an actual pixel width (e.g. 260) instead of the preset index; corrupted config replayed after the enum range changed; UI slider computed the index incorrectly.

Related errors


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