{"record":{"id":"3151e7ac30d51dee","repo":"siyuan-note/siyuan","slug":"invalid-card-size-preset-v","errorCode":null,"errorMessage":"invalid card size preset [%v]","messagePattern":"invalid card size preset \\[(.+?)\\]","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"kernel/model/attribute_view.go","lineNumber":1652,"sourceCode":"\treturn\n}\n\nfunc (tx *Transaction) doSetAttrViewCardSize(operation *Operation) (ret *TxErr) {\n\terr := setAttrViewCardSize(operation)\n\tif err != nil {\n\t\treturn &TxErr{code: TxErrHandleAttributeView, id: operation.AvID, msg: err.Error()}\n\t}\n\treturn\n}\n\nfunc setAttrViewCardSize(operation *Operation) (err error) {\n\tvalue, err := getAttrViewOperationNumber(operation)\n\tif nil != err {\n\t\treturn\n\t}\n\tsize := av.CardSize(value)\n\tif value != math.Trunc(value) || size < av.CardSizeSmall || av.CardSizeLarge < size {\n\t\treturn fmt.Errorf(\"invalid card size preset [%v]\", value)\n\t}\n\n\tattrView, err := av.ParseAttributeView(operation.AvID)\n\tif err != nil {\n\t\treturn\n\t}\n\n\tview, err := getAttrViewViewByBlockID(attrView, operation.BlockID)\n\tif err != nil {\n\t\treturn\n\t}\n\n\tswitch view.LayoutType {\n\tcase av.LayoutTypeTable:\n\t\treturn\n\tcase av.LayoutTypeGallery:\n\t\tview.Gallery.CardSize = size\n\t\tview.Gallery.CardWidth = av.CardWidthBySize(size)","sourceCodeStart":1634,"sourceCodeEnd":1670,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/251596fc0de2f9528c00c224252fd073a99973f4/kernel/model/attribute_view.go#L1634-L1670","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Send only 0, 1, or 2 (small / medium / large) as an integer JSON number.","If you need an exact pixel width, use the separate action setAttrViewCardWidth (error 433) which accepts 140–600.","Keep the preset index and the derived width in sync via av.CardWidthBySize on the client."],"exampleFix":"// before: sending a pixel value as the preset\ntransaction({ op: \"setAttrViewCardSize\", data: 260 })\n\n// after: send the preset index (1 = medium, derives width 260)\ntransaction({ op: \"setAttrViewCardSize\", data: 1 })","handlingStrategy":"validation","validationCode":"// Card size is an enum index, not pixels: only 0,1,2 are valid.\nif (![0,1,2].includes(data) || !Number.isInteger(data)) {\n  throw new Error('card size preset must be 0, 1, or 2')\n}","typeGuard":"function isCardSizePreset(v: unknown): v is number {\n  return typeof v === 'number' && Number.isInteger(v) && v >= 0 && v <= 2\n}","tryCatchPattern":null,"preventionTips":["Send the preset index (0/1/2), not a pixel value.","Use setAttrViewCardWidth for an exact pixel width (140–600).","Let CardWidthBySize derive the width from the preset client-side."],"tags":["attribute-view","av","gallery","kanban","card","validation","transaction"],"backgroundTag":null,"analyzedSha":"251596fc0de2f9528c00c224252fd073a99973f4","analyzedAt":"2026-08-12T21:18:37.123Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}