siyuan-note/siyuan · error
marshal inline styles failed
Error message
marshal inline styles failed: %w
What it means
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.
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.
Defensive patterns
Strategy: try-catch
Try / catch
if err != nil && strings.Contains(err.Error(), "marshal inline styles failed") {
// log the wrapped cause; resubmit a simplified styles payload
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: Custom builds or patched structs that add non-JSON-serializable fields to InlineStyles; memory/resource exhaustion during marshal on very large style collections.
Understand the failure class
Background: json.Marshal / "failed to marshal" errors in Go: why "unsupported type" happens and how to fix it — this error's family across 22 libraries.
Related errors
- builtin color must not be null
- builtin style must not be null
- encode session data failed
- invalid inline styles data
- marshal AI editor actions failed
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/46e3b8a51c3a1955.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/model/inline_style.go:279
if 0 < len(changedCustomColorIndexes) {
removedIndexes := removedAttributeViewCustomColorIndexes(currentAV.Colors, ret.AV.Colors)
customColorUsage, err = workspaceAttributeViewCustomColorUsage(0 < len(removedIndexes))
if err != nil {
return nil, false, err
}
for _, avID := range sortedAttributeViewUsageIDs(customColorUsage) {
indexes := customColorUsage[avID]
for index := range removedIndexes {
if _, used := indexes[index]; used {
return nil, false, fmt.Errorf("attribute view custom color [%d] is still in use by attribute view [%s]",
index, avID)
}
}
}
}
data, err := gulu.JSON.MarshalIndentJSON(ret, "", " ")
if err != nil {
return nil, false, fmt.Errorf("marshal inline styles failed: %w", err)
}
if maxInlineStylesFileSize < len(data) {
return nil, false, fmt.Errorf("inline styles file exceeds the %d byte limit", maxInlineStylesFileSize)
}
dataPath := inlineStylesPath()
oldData, readErr := filelock.ReadFile(dataPath)
if readErr != nil && !os.IsNotExist(readErr) {
return nil, false, fmt.Errorf("read inline styles failed: %w", readErr)
}
if bytes.Equal(oldData, data) {
cacheWorkspaceAVPalette(ret.AV)
return ret, false, nil
}
if err = os.MkdirAll(filepath.Dir(dataPath), 0755); err != nil {
return nil, false, fmt.Errorf("create inline styles directory failed: %w", err)
}View on GitHub (pinned to 9f775e8a12)