{"record":{"id":"94defde80b6107df","repo":"siyuan-note/siyuan","slug":"inline-styles-file-exceeds-the-d-byte-limit","errorCode":null,"errorMessage":"inline styles file exceeds the %d byte limit","messagePattern":"inline styles file exceeds the (.+?) byte limit","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/inline_style.go","lineNumber":282,"sourceCode":"\t\tif err != nil {\n\t\t\treturn nil, false, err\n\t\t}\n\t\tfor _, avID := range sortedAttributeViewUsageIDs(customColorUsage) {\n\t\t\tindexes := customColorUsage[avID]\n\t\t\tfor index := range removedIndexes {\n\t\t\t\tif _, used := indexes[index]; used {\n\t\t\t\t\treturn nil, false, fmt.Errorf(\"attribute view custom color [%d] is still in use by attribute view [%s]\",\n\t\t\t\t\t\tindex, avID)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tdata, err := gulu.JSON.MarshalIndentJSON(ret, \"\", \"  \")\n\tif err != nil {\n\t\treturn nil, false, fmt.Errorf(\"marshal inline styles failed: %w\", err)\n\t}\n\tif maxInlineStylesFileSize < len(data) {\n\t\treturn nil, false, fmt.Errorf(\"inline styles file exceeds the %d byte limit\", maxInlineStylesFileSize)\n\t}\n\n\tdataPath := inlineStylesPath()\n\toldData, readErr := filelock.ReadFile(dataPath)\n\tif readErr != nil && !os.IsNotExist(readErr) {\n\t\treturn nil, false, fmt.Errorf(\"read inline styles failed: %w\", readErr)\n\t}\n\tif bytes.Equal(oldData, data) {\n\t\tcacheWorkspaceAVPalette(ret.AV)\n\t\treturn ret, false, nil\n\t}\n\n\tif err = os.MkdirAll(filepath.Dir(dataPath), 0755); err != nil {\n\t\treturn nil, false, fmt.Errorf(\"create inline styles directory failed: %w\", err)\n\t}\n\tif err = filelock.WriteFile(dataPath, data); err != nil {\n\t\treturn nil, false, fmt.Errorf(\"write inline styles failed: %w\", err)\n\t}","sourceCodeStart":264,"sourceCodeEnd":300,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/kernel/model/inline_style.go#L264-L300","documentation":"Before writing, the serialized inline-styles JSON is size-checked against maxInlineStylesFileSize to keep the single workspace styles file small and cheap to sync. When the marshaled payload exceeds the limit, the update is rejected with the byte limit included in the message. No partial write occurs.","triggerScenarios":"Adding a very large number of custom color entries to the workspace palette; accumulating many per-AV usage mappings over time; a malicious or buggy bulk import that inflates styles.Styles.","commonSituations":"Long-lived workspaces where old palettes are never pruned; scripted palette generation with generated IDs; importing palette data exported from a much larger workspace.","solutions":["Check maxInlineStylesFileSize in kernel/model/inline_style.go and trim styles.Styles to fit under it","Remove unused custom color entries (only those not reported by workspaceAttributeViewCustomColorUsage)","Split colors across attribute views using default palette entries instead of many custom colors","Verify the payload is not accidentally duplicated (e.g. merging current styles into the new payload twice)"],"exampleFix":"// before\nstyles.Styles = allHistoryColors // hundreds of entries, file exceeds limit\n// after\nusage, _ := workspaceAttributeViewCustomColorUsage(true)\nstyles.Styles = pruneUnusedColors(allHistoryColors, usage) // keep only referenced colors","handlingStrategy":"validation","validationCode":"data, _ := json.MarshalIndent(styles, \"\", \"  \")\nif len(data) > model.MaxInlineStylesFileSize {\n    return fmt.Errorf(\"styles payload %d bytes exceeds limit\", len(data))\n}","typeGuard":null,"tryCatchPattern":"_, _, err := model.SetInlineStyles(styles)\nif err != nil && strings.Contains(err.Error(), \"byte limit\") {\n    // prune unused colors and retry with a smaller payload\n}","preventionTips":["Prune unused custom colors periodically using the usage map","Do not bulk-import unbounded palette exports into a workspace","Estimate payload size before writing when programmatically generating styles"],"tags":["go","file-size","limits"],"backgroundTag":"file-size-limit-exceeded","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}