{"record":{"id":"d5573b60c5254d62","repo":"siyuan-note/siyuan","slug":"invalid-card-aspect-ratio-preset-v","errorCode":null,"errorMessage":"invalid card aspect ratio preset [%v]","messagePattern":"invalid card aspect ratio preset \\[(.+?)\\]","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"kernel/model/attribute_view.go","lineNumber":1155,"sourceCode":"\t}\n}\n\nfunc (tx *Transaction) doSetAttrViewCardAspectRatio(operation *Operation) (ret *TxErr) {\n\terr := setAttrViewCardAspectRatio(operation)\n\tif err != nil {\n\t\treturn &TxErr{code: TxErrHandleAttributeView, id: operation.AvID, msg: err.Error()}\n\t}\n\treturn\n}\n\nfunc setAttrViewCardAspectRatio(operation *Operation) (err error) {\n\tvalue, err := getAttrViewOperationNumber(operation)\n\tif nil != err {\n\t\treturn\n\t}\n\tratio := av.CardAspectRatio(value)\n\tif value != math.Trunc(value) || ratio < av.CardAspectRatio16_9 || av.CardAspectRatio1_1 < ratio {\n\t\treturn fmt.Errorf(\"invalid card aspect ratio 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.CardAspectRatio = ratio\n\t\tview.Gallery.CardAspectRatioValue = av.CardAspectRatioValueByPreset(ratio)","sourceCodeStart":1137,"sourceCodeEnd":1173,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/251596fc0de2f9528c00c224252fd073a99973f4/kernel/model/attribute_view.go#L1137-L1173","documentation":"Returned by setAttrViewCardAspectRatio (attribute_view.go:1155), dispatched through the transaction action \"setAttrViewCardAspectRatio\". The operation.Data must be a float64 (else error 437 from getAttrViewOperationNumber), the value must be a whole number (value == math.Trunc(value)), and av.CardAspectRatio(value) must fall within [CardAspectRatio16_9=0 .. CardAspectRatio1_1=6]. The error means the preset index is fractional or outside the 0–6 enum range.","triggerScenarios":"Frontend sends a setAttrViewCardAspectRatio transaction with data that is a non-integer (e.g. 2.5) or an integer outside 0–6 (e.g. -1 or 7). The value selects one of the seven aspect-ratio presets (16:9, 9:16, 4:3, 3:4, 3:2, 2:3, 1:1) for a gallery or kanban view.","commonSituations":"Plugin constructs the operation manually and passes the raw aspect-ratio number (e.g. 1.78) instead of the preset enum index; stale frontend build whose preset list drifted from the kernel enum; corrupted/persisted config replayed with a bad value.","solutions":["Send one of the documented preset indices 0–6 (matching CardAspectRatio16_9 .. CardAspectRatio1_1), as an integer JSON number.","If you need an arbitrary ratio, use the separate action setAttrViewCardAspectRatioValue (error 427) which accepts a free-form width/height float in [0.25, 2.5].","Re-derive the index from the UI preset selector instead of computing it from the ratio."],"exampleFix":"// before: sending the computed ratio as the preset\ntransaction({ op: \"setAttrViewCardAspectRatio\", data: 16/9 })\n\n// after: send the preset enum index (0 = 16:9)\ntransaction({ op: \"setAttrViewCardAspectRatio\", data: 0 })","handlingStrategy":"validation","validationCode":"// Only send integer preset indices 0..6 for setAttrViewCardAspectRatio.\nconst VALID = [0,1,2,3,4,5,6]\nif (!Number.isInteger(data) || !VALID.includes(data)) {\n  throw new Error(`aspect ratio preset must be one of ${VALID}`)\n}","typeGuard":"function isCardAspectRatioPreset(v: unknown): v is number {\n  return typeof v === 'number' && Number.isInteger(v) && v >= 0 && v <= 6\n}","tryCatchPattern":null,"preventionTips":["Send the preset enum index (0–6), not the computed ratio.","For arbitrary ratios use the separate setAttrViewCardAspectRatioValue action.","Keep the client preset list in sync with the av.CardAspectRatio iota enum."],"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-12T23:17:12.415Z"}