{"record":{"id":"46e3b8a51c3a1955","repo":"siyuan-note/siyuan","slug":"marshal-inline-styles-failed-w","errorCode":null,"errorMessage":"marshal inline styles failed: %w","messagePattern":"marshal inline styles failed: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/inline_style.go","lineNumber":279,"sourceCode":"\tif 0 < len(changedCustomColorIndexes) {\n\t\tremovedIndexes := removedAttributeViewCustomColorIndexes(currentAV.Colors, ret.AV.Colors)\n\t\tcustomColorUsage, err = workspaceAttributeViewCustomColorUsage(0 < len(removedIndexes))\n\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}","sourceCodeStart":261,"sourceCodeEnd":297,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/inline_style.go#L261-L297","documentation":"After normalizing and merging the styles, the kernel serializes the result with gulu.JSON.MarshalIndentJSON before persisting it. If marshalling fails, the operation aborts and wraps the underlying error. This is unexpected because the input has already been validated and normalized.","triggerScenarios":"setInlineStylesData reaching the serialization step with data gulu cannot marshal — practically only via exotic values in styles content (e.g. unsupported types introduced through custom Go struct fields) or a marshalling library failure.","commonSituations":"Custom builds or patched structs that add non-JSON-serializable fields to InlineStyles; memory/resource exhaustion during marshal on very large style collections.","solutions":["Inspect the wrapped cause (%w) in the error message to identify the unserializable value.","Simplify or reduce the submitted styles payload and retry.","If a custom struct field causes it, add a json tag or omit the field; verify with a local gulu.JSON.MarshalIndentJSON call in a test."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"marshal inline styles failed\") {\n    // log the wrapped cause; resubmit a simplified styles payload\n}","preventionTips":["Keep the styles payload to plain JSON-safe values","Test custom struct extensions with gulu.JSON marshalling before shipping","Retry once with a minimal payload to isolate the offending value"],"tags":["json","serialization","inline-styles"],"backgroundTag":"json-marshal-failed","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"}