{"record":{"id":"e9d21e67b5521114","repo":"siyuan-note/siyuan","slug":"invalid-attribute-view-column-widths","errorCode":null,"errorMessage":"invalid attribute view column widths","messagePattern":"invalid attribute view column widths","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/attribute_view.go","lineNumber":6337,"sourceCode":"\t\treturn\n\t}\n\n\terr = av.SaveAttributeView(attrView)\n\treturn\n}\n\nfunc (tx *Transaction) doSetAttrViewColumnsWidth(operation *Operation) (ret *TxErr) {\n\terr := setAttributeViewColsWidth(operation)\n\tif err != nil {\n\t\treturn &TxErr{code: TxErrHandleAttributeView, id: operation.AvID, msg: err.Error()}\n\t}\n\treturn\n}\n\nfunc setAttributeViewColsWidth(operation *Operation) (err error) {\n\twidthData, ok := operation.Data.(map[string]any)\n\tif !ok {\n\t\treturn fmt.Errorf(\"invalid attribute view column widths\")\n\t}\n\twidths := map[string]string{}\n\tfor id, value := range widthData {\n\t\twidth, valueOK := value.(string)\n\t\tif !valueOK {\n\t\t\treturn fmt.Errorf(\"invalid width for attribute view column [%s]\", id)\n\t\t}\n\t\twidths[id] = width\n\t}\n\n\tattrView, err := av.ParseAttributeView(operation.AvID)\n\tif err != nil {\n\t\treturn err\n\t}\n\tview, err := getAttrViewViewByBlockID(attrView, operation.BlockID)\n\tif err != nil {\n\t\treturn err\n\t}","sourceCodeStart":6319,"sourceCodeEnd":6355,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/251596fc0de2f9528c00c224252fd073a99973f4/kernel/model/attribute_view.go#L6319-L6355","documentation":"Thrown by setAttributeViewColsWidth when operation.Data cannot be asserted to map[string]any. The column-width operation expects a JSON object mapping column ID -> width string; any other shape (array, number, string, nil) fails the type assertion immediately.","triggerScenarios":"A frontend or API caller sends the widths payload as the wrong JSON type (e.g. an array of pairs, a single number, or omits Data entirely). Also reached by an undo replay whose captured Data was serialized differently.","commonSituations":"Client-side serialization bug; version skew where an older client uses a different payload schema; a manually crafted HTTP request to the transaction endpoint with a malformed body.","solutions":["Ensure the operation Data is a JSON object { [columnID: string]: string } before sending the transaction.","On the client, build the payload with Object.fromEntries rather than pushing into an array.","If integrating via the HTTP API, validate the JSON shape against the Operation.Data contract before posting."],"exampleFix":"// before\nop.Data = [['col1', '200px'], ['col2', '120px']] // array of pairs\n// after\nop.Data = { col1: '200px', col2: '120px' } // plain object","handlingStrategy":"type-guard","validationCode":"function isWidthMap(d) {\n  return d != null && typeof d === 'object' && !Array.isArray(d) && Object.values(d).every(v => typeof v === 'string')\n}\nif (!isWidthMap(op.data)) { /* rebuild as object { [id]: string } */ }","typeGuard":"type WidthMap = Record<string, string>\nfunction isWidthMap(v: unknown): v is WidthMap {\n  if (typeof v !== 'object' || v === null || Array.isArray(v)) return false\n  return Object.values(v).every(x => typeof x === 'string')\n}","tryCatchPattern":null,"preventionTips":["Always build the widths payload as a plain object, not an array of pairs.","Pin the operation schema in a shared client type and unit-test it."],"tags":["attribute-view","payload-validation","column-width","transaction"],"backgroundTag":null,"analyzedSha":"251596fc0de2f9528c00c224252fd073a99973f4","analyzedAt":"2026-08-12T21:18:37.123Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}