siyuan-note/siyuan · error
builtin style must not be null
Error message
builtin style must not be null
What it means
builtin.styles entries are validated the same way as colors: any null element in the styles array of inline-styles.json is rejected because the normalizer would otherwise dereference a nil *InlineStyleBuiltinStyle when reading its ID and themes.
Solutions
- Remove the null element from builtin.styles in /storage/inline-styles.json
- Ensure each entry has a valid id (error|warning|info|success) plus light and dark themes
- Validate the JSON before writing it back; keep IDs within the fixed builtin set
- If generated by code, only append non-nil &InlineStyleBuiltinStyle{...} values
Example fix
// before
"styles": [ {"id": "error", ...}, null ]
// after
"styles": [ {"id": "error", "light": {...}, "dark": {...}} ] Defensive patterns
Strategy: validation
Validate before calling
const bad = (cfg.builtin?.styles ?? []).findIndex(s => s == null);
if (bad !== -1) throw new Error(`builtin.styles[${bad}] is null`); Type guard
function isBuiltinStyle(s) { return s !== null && typeof s === 'object' && typeof s.id === 'string'; } Try / catch
if _, err := setInlineStylesData(styles, currentAV); err != nil {
if strings.Contains(err.Error(), "builtin style must not be null") { /* repair inline-styles.json and retry */ }
return err
} Prevention
- Keep builtin.styles a fixed 4-element array (error, warning, info, success) — never splice nulls
- Use the app's style settings to toggle/hide builtin styles rather than editing the file
- Validate JSON after any scripted rewrite
- Restore from backup if a sync merge corrupts the array
When it happens
Trigger: setInlineStylesData or loadInlineStyles reads inline-styles.json containing `"styles": [null]` or a Go caller passing a Styles slice containing nil pointers.
Common situations: Manual JSON editing leaving a dangling null; a sync or merge tool emitting null placeholders; programmatic generation that appends an empty/zero entry to the slice.
Related errors
- builtin color must not be null
- duplicate builtin color index
- duplicate builtin style ID
- invalid builtin style ID
- invalid inline styles data
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/02bf6277fc6848f2.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/model/inline_style.go:737
if _, exists := colorIndexes[color.Index]; exists {
return nil, fmt.Errorf("duplicate builtin color index [%d]", color.Index)
}
colorIndexes[color.Index] = struct{}{}
light, dark, err := normalizeInlineStyleThemePair(color.Light, color.Dark, fmt.Sprintf("builtin color [%d]", color.Index))
if err != nil {
return nil, err
}
ret.Colors = append(ret.Colors, &InlineStyleBuiltinColor{Index: color.Index, Light: light, Dark: dark})
}
sort.Slice(ret.Colors, func(i, j int) bool {
return ret.Colors[i].Index < ret.Colors[j].Index
})
styleIDs := make(map[string]struct{}, len(builtin.Styles))
for _, style := range builtin.Styles {
if style == nil {
return nil, errors.New("builtin style must not be null")
}
id := strings.TrimSpace(style.ID)
if _, valid := builtinStyleOrder[id]; !valid {
return nil, fmt.Errorf("invalid builtin style ID [%s]", id)
}
if _, exists := styleIDs[id]; exists {
return nil, fmt.Errorf("duplicate builtin style ID [%s]", id)
}
styleIDs[id] = struct{}{}
light, dark, err := normalizeInlineStyleThemePair(style.Light, style.Dark, "builtin style ["+id+"]")
if err != nil {
return nil, err
}
ret.Styles = append(ret.Styles, &InlineStyleBuiltinStyle{ID: id, Light: light, Dark: dark})
}
sort.Slice(ret.Styles, func(i, j int) bool {
return builtinStyleOrder[ret.Styles[i].ID] < builtinStyleOrder[ret.Styles[j].ID]View on GitHub (pinned to 9f775e8a12)