siyuan-note/siyuan · error

invalid card width [ ]

Error message

invalid card width [%v]

What it means

setAttrViewCardWidth validates the width number is finite, an integer, and within [av.CardWidthMin, av.CardWidthMax]; NaN, Infinity, fractions, and out-of-range values are rejected before the attribute view is parsed. Card width is a bounded integer setting, not an arbitrary number.

Solutions

  1. Clamp the width to av.CardWidthMin..av.CardWidthMax and Math.round it before enqueueing the operation.
  2. Guard the computation with Number.isFinite and reject non-numeric input early.
  3. Check the current kernel constants for the valid range if the call previously worked.

Example fix

// before
setCardWidth(avID, rect.width); // 213.33333
// after
const w = Math.round(rect.width);
if (Number.isFinite(w) && w >= CardWidthMin && w <= CardWidthMax) setCardWidth(avID, w);
Defensive patterns

Strategy: validation

Validate before calling

const n = Number(value);
if (!Number.isFinite(n) || !Number.isInteger(n) || n < CardWidthMin || n > CardWidthMax) throw new RangeError('card width out of range');

Type guard

const isValidCardWidth = (v: unknown): v is number => typeof v === 'number' && Number.isFinite(v) && Number.isInteger(v) && v >= CardWidthMin && v <= CardWidthMax;

Try / catch

try { await setCardWidth(avID, value); } catch (e) { if (String(e).includes('invalid card width')) { await setCardWidth(avID, clamp(Math.round(value), CardWidthMin, CardWidthMax)); } else throw e; }

Prevention

When it happens

Trigger: Sending a setAttrViewCardWidth operation with a float (e.g. from getBoundingClientRect), NaN/Infinity from a bad computation, or a width below CardWidthMin / above CardWidthMax.

Common situations: Sub-pixel measurements passed unrounded; division by zero in a ratio-derived width; plugin constants predating the introduction of min/max clamps; manual API calls with percent values instead of the expected integer.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


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

Appendix: source

Thrown at kernel/model/attribute_view.go:1840

	err = av.SaveAttributeView(attrView)
	return
}

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

func setAttrViewCardWidth(operation *Operation) (err error) {
	value, err := getAttrViewOperationNumber(operation)
	if nil != err {
		return
	}
	if math.IsNaN(value) || math.IsInf(value, 0) || value != math.Trunc(value) ||
		value < av.CardWidthMin || av.CardWidthMax < value {
		return fmt.Errorf("invalid card width [%v]", value)
	}
	width := int(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.CardWidth = width
	case av.LayoutTypeKanban:

View on GitHub (pinned to 9f775e8a12)