siyuan-note/siyuan · error
unmarshal inline styles failed
Error message
unmarshal inline styles failed: %w
What it means
Error from loadInlineStyles when the persisted inline-styles JSON file exists and is within the size limit but fails gulu.JSON.UnmarshalJSON — the file is corrupt (truncated write or manual edit), so inline styles cannot be loaded.
Solutions
- Validate the file JSON syntax with a JSON linter and fix the syntax error
- Restore the file from backup or sync history
- Delete the corrupt file; the kernel will treat it as missing and start with defaults
Example fix
// before: file contains truncated JSON
{"version":2,"styles":[{"id":"20240101120000-abc
// after: complete valid JSON (or delete the file to regenerate)
{"version":2,"styles":[]} Defensive patterns
Strategy: validation
Validate before calling
const parsed = JSON.parse(fs.readFileSync(inlineStylesPath, 'utf8')); // throws before API call if malformed
Type guard
const looksLikeInlineStyles = (o) => o && typeof o === 'object' && Array.isArray(o.styles);
Try / catch
try {
await fetchPost('/api/attr/getInlineStyles', {});
} catch (e) {
if (String(e).includes('unmarshal inline styles failed')) {
// restore file from backup or delete it to regenerate defaults
}
} Prevention
- Validate JSON after every manual edit
- Let the kernel write the file rather than editing it in place
- Keep a known-good backup of the file
When it happens
Trigger: Any inline-styles API when data/storage inline styles file contains malformed JSON (truncated write, manual editing mistake, wrong file restored).
Common situations: Editing the JSON by hand with a syntax error, an interrupted kernel write leaving a truncated file, or pasting another config's content into it.
Understand the failure class
Background: "failed to unmarshal" / json.Unmarshal errors: why parsing a response into a Go struct fails and how to fix it — this error's family across 23 libraries.
Related errors
- builtin color must not be null
- builtin style must not be null
- decode existing session data failed
- invalid attribute view JSON
- invalid document JSON
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/a788f86fe5f6ae91.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/model/inline_style.go:471
func isInlineStylesRepoPath(filePath string) bool {
return filePath == inlineStylesRepoPath
}
func loadInlineStyles() (ret *InlineStyles, err error) {
ret = newEmptyInlineStyles()
data, err := filelock.ReadFile(inlineStylesPath())
if os.IsNotExist(err) {
return ret, nil
}
if err != nil {
return nil, fmt.Errorf("read inline styles failed: %w", err)
}
if maxInlineStylesFileSize < len(data) {
return nil, fmt.Errorf("inline styles file exceeds the %d byte limit", maxInlineStylesFileSize)
}
if err = gulu.JSON.UnmarshalJSON(data, ret); err != nil {
return nil, fmt.Errorf("unmarshal inline styles failed: %w", err)
}
if ret.Version != 1 && ret.Version != InlineStylesVersion {
return nil, fmt.Errorf("unsupported inline styles version [%d]", ret.Version)
}
ret.Styles, err = normalizeInlineStyles(ret.Styles, false)
if err != nil {
return nil, fmt.Errorf("invalid inline styles data: %w", err)
}
ret.Builtin, err = normalizeInlineStyleBuiltin(ret.Builtin)
if err != nil {
return nil, fmt.Errorf("invalid inline styles data: %w", err)
}
ret.Order = normalizeInlineStyleOrder(ret.Order, ret.Styles)
ret.AV, err = normalizeInlineStyleAV(ret.AV, false)
if err != nil {
return nil, fmt.Errorf("invalid inline styles data: %w", err)
}
ret.Version = InlineStylesVersionView on GitHub (pinned to 9f775e8a12)