siyuan-note/siyuan · error
invalid card aspect ratio preset
Error message
invalid card aspect ratio preset [%v]
What it means
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.
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
Example fix
// before
ops.push({ action: 'setAttrViewCardAspectRatio', avID, data: 1.77 })
// after
ops.push({ action: 'setAttrViewCardAspectRatio', avID, data: CardAspectRatio16_9 }) Defensive patterns
Strategy: validation
Validate before calling
// value must be an integral preset within the allowed range
function isValidCardAspectRatio(v) {
return Number.isInteger(v) && v >= CARD_ASPECT_RATIO_16_9 && v <= CARD_ASPECT_RATIO_1_1;
}
if (!isValidCardAspectRatio(value)) throw new Error('use a preset constant'); Type guard
const isPresetRatio = (v) => Number.isInteger(v) && v >= 0 && v <= 2; // adjust to exported preset range
Try / catch
try { await setAttrViewCardAspectRatio(avID, value) } catch (e) {
if (e.message.includes('invalid card aspect ratio preset')) {
showPresetPicker(); // let user choose a valid preset
}
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- ErrInvalidColumnAlign
- invalid card layout [ ]
- invalid card size preset
- invalid new item template field value mode
- invalid new item template target type
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/d5573b60c5254d62.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/model/attribute_view.go:1301
}
}
func (tx *Transaction) doSetAttrViewCardAspectRatio(operation *Operation) (ret *TxErr) {
err := setAttrViewCardAspectRatio(operation)
if err != nil {
return &TxErr{code: TxErrHandleAttributeView, id: operation.AvID, msg: err.Error()}
}
return
}
func setAttrViewCardAspectRatio(operation *Operation) (err error) {
value, err := getAttrViewOperationNumber(operation)
if nil != err {
return
}
ratio := av.CardAspectRatio(value)
if value != math.Trunc(value) || ratio < av.CardAspectRatio16_9 || av.CardAspectRatio1_1 < ratio {
return fmt.Errorf("invalid card aspect ratio preset [%v]", 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.CardAspectRatio = ratio
view.Gallery.CardAspectRatioValue = av.CardAspectRatioValueByPreset(ratio)View on GitHub (pinned to 9f775e8a12)