siyuan-note/siyuan · error

invalid card size preset

Error message

invalid card size preset [%v]

What it means

setAttrViewCardSize validates that the numeric value is an integer that maps to a defined av.CardSize preset between CardSizeSmall and CardSizeLarge; fractional values or out-of-preset integers are rejected. Card size is an enum-like preset, not a free-form number.

Solutions

  1. Pass only defined av.CardSize presets (Math.floor the value and check it is within CardSizeSmall..CardSizeLarge).
  2. Convert any pixel-based sizing in the caller to the nearest valid preset before sending the operation.
  3. Update plugin constants if the preset enum changed between kernel versions.

Example fix

// before
setCardSize(avID, el.offsetWidth); // pixels
// after
const preset = Math.min(CardSizeLarge, Math.max(CardSizeSmall, Math.round(el.offsetWidth / 200)));
setCardSize(avID, preset);
Defensive patterns

Strategy: validation

Validate before calling

const n = Number(value);
if (!Number.isInteger(n) || n < CardSizeSmall || n > CardSizeLarge) throw new RangeError('invalid card size preset');

Type guard

const isCardSize = (v: unknown): v is number => Number.isInteger(v) && v >= CardSizeSmall && v <= CardSizeLarge;

Try / catch

try { await setCardSize(avID, value); } catch (e) { if (String(e).includes('invalid card size preset')) { await setCardSize(avID, CardSizeSmall); } else throw e; }

Prevention

When it happens

Trigger: Sending a setAttrViewCardSize transaction operation whose number is fractional (e.g. 1.5) or outside the small..large preset range (negative, > av.CardSizeLarge).

Common situations: Plugin treats card size as a pixel value and passes raw sizes; UI slider emits floats; stale code using removed preset indices.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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

Appendix: source

Thrown at kernel/model/attribute_view.go:1798

	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 9f775e8a12)