siyuan-note/siyuan · warning

invalid card width [%v]

Error message

invalid card width [%v]

What it means

Returned by setAttrViewCardWidth (attribute_view.go:1694), dispatched through the transaction action "setAttrViewCardWidth". The value must be a finite float64, a whole number (value == math.Trunc(value)), and within [av.CardWidthMin=140, av.CardWidthMax=600]. It is then truncated to int and stored as the pixel width.

Source

Thrown at kernel/model/attribute_view.go:1694

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

Solutions

  1. Clamp the width to [140, 600] and round to an integer before sending.
  2. Reflect the same bounds in the UI control so the user cannot enter an out-of-range value.
  3. If using a size preset instead, use setAttrViewCardSize and let CardWidthBySize compute the width.

Example fix

// before: raw slider value, possibly out of range
transaction({ op: "setAttrViewCardWidth", data: sliderValue })

// after: clamp and integerize
const width = Math.round(Math.min(600, Math.max(140, sliderValue)))
transaction({ op: "setAttrViewCardWidth", data: width })
Defensive patterns

Strategy: validation

Validate before calling

// Clamp and round the width to an integer in [140, 600].
if (!Number.isFinite(value)) throw new Error('width must be finite')
const width = Math.round(Math.min(600, Math.max(140, value)))

Type guard

function isValidCardWidth(v: unknown): v is number {
  return typeof v === 'number' && Number.isFinite(v) && Number.isInteger(v) && v >= 140 && v <= 600
}

Prevention

When it happens

Trigger: Frontend sends a card width that is NaN/Inf, fractional, below 140, or above 600. This is the free-form width path for gallery/kanban cards, independent of the size preset.

Common situations: UI slider allowed a value outside 140–600; plugin submitted a fractional CSS width; negative or zero sent by a reset control that did not clamp.

Related errors


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