{"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":"error","filePath":"kernel/model/attribute_view.go","lineNumber":1301,"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":1283,"sourceCodeEnd":1319,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/attribute_view.go#L1283-L1319","documentation":"A transaction operation tried to set an attribute view's card (flashcard) aspect ratio to a value that is not one of the defined presets. The value must be an integer between av.CardAspectRatio16_9 and av.CardAspectRatio1_1 inclusive; anything else (fractional, out-of-range, or non-numeric) is rejected before the attribute view is parsed.","triggerScenarios":"doSetAttrViewCardAspectRatio handling an operation whose number value is fractional (e.g. 2.5), outside the preset enum range (below 16:9 or above 1:1), or otherwise not an integral preset index.","commonSituations":"Plugins/scripts calling the set-attribute-view-card-aspect-ratio transaction with a raw ratio like 1.7777 instead of the preset constant; UI sending an unvalidated user-typed value; version drift where a plugin uses a preset not present in the running kernel.","solutions":["Pass one of the exported preset values (av.CardAspectRatio16_9 ... CardAspectRatio1_1) instead of a raw number","Ensure the value is an integer (truncate/validate before sending the operation)","Update the plugin to the current petal/plugin API preset list if it uses stale constants"],"exampleFix":"// before\nops.push({ action: 'setAttrViewCardAspectRatio', avID, data: 1.77 })\n// after\nops.push({ action: 'setAttrViewCardAspectRatio', avID, data: CardAspectRatio16_9 })","handlingStrategy":"validation","validationCode":"// value must be an integral preset within the allowed range\nfunction isValidCardAspectRatio(v) {\n  return Number.isInteger(v) && v >= CARD_ASPECT_RATIO_16_9 && v <= CARD_ASPECT_RATIO_1_1;\n}\nif (!isValidCardAspectRatio(value)) throw new Error('use a preset constant');","typeGuard":"const isPresetRatio = (v) => Number.isInteger(v) && v >= 0 && v <= 2; // adjust to exported preset range","tryCatchPattern":"try { await setAttrViewCardAspectRatio(avID, value) } catch (e) {\n  if (e.message.includes('invalid card aspect ratio preset')) {\n    showPresetPicker(); // let user choose a valid preset\n  }\n}","preventionTips":["Always send exported preset constants, never raw ratios like 1.77","Validate integer-ness and range before building the transaction operation","Keep plugin constants in sync with the current petal/kernel preset enum"],"tags":["validation","enum","attribute-view"],"backgroundTag":"invalid-enum-value","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}