{"record":{"id":"02bf6277fc6848f2","repo":"siyuan-note/siyuan","slug":"builtin-style-must-not-be-null","errorCode":null,"errorMessage":"builtin style must not be null","messagePattern":"builtin style must not be null","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/inline_style.go","lineNumber":737,"sourceCode":"\t\tif _, exists := colorIndexes[color.Index]; exists {\n\t\t\treturn nil, fmt.Errorf(\"duplicate builtin color index [%d]\", color.Index)\n\t\t}\n\t\tcolorIndexes[color.Index] = struct{}{}\n\n\t\tlight, dark, err := normalizeInlineStyleThemePair(color.Light, color.Dark, fmt.Sprintf(\"builtin color [%d]\", color.Index))\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tret.Colors = append(ret.Colors, &InlineStyleBuiltinColor{Index: color.Index, Light: light, Dark: dark})\n\t}\n\tsort.Slice(ret.Colors, func(i, j int) bool {\n\t\treturn ret.Colors[i].Index < ret.Colors[j].Index\n\t})\n\n\tstyleIDs := make(map[string]struct{}, len(builtin.Styles))\n\tfor _, style := range builtin.Styles {\n\t\tif style == nil {\n\t\t\treturn nil, errors.New(\"builtin style must not be null\")\n\t\t}\n\t\tid := strings.TrimSpace(style.ID)\n\t\tif _, valid := builtinStyleOrder[id]; !valid {\n\t\t\treturn nil, fmt.Errorf(\"invalid builtin style ID [%s]\", id)\n\t\t}\n\t\tif _, exists := styleIDs[id]; exists {\n\t\t\treturn nil, fmt.Errorf(\"duplicate builtin style ID [%s]\", id)\n\t\t}\n\t\tstyleIDs[id] = struct{}{}\n\n\t\tlight, dark, err := normalizeInlineStyleThemePair(style.Light, style.Dark, \"builtin style [\"+id+\"]\")\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tret.Styles = append(ret.Styles, &InlineStyleBuiltinStyle{ID: id, Light: light, Dark: dark})\n\t}\n\tsort.Slice(ret.Styles, func(i, j int) bool {\n\t\treturn builtinStyleOrder[ret.Styles[i].ID] < builtinStyleOrder[ret.Styles[j].ID]","sourceCodeStart":719,"sourceCodeEnd":755,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/inline_style.go#L719-L755","documentation":"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.","triggerScenarios":"setInlineStylesData or loadInlineStyles reads inline-styles.json containing `\"styles\": [null]` or a Go caller passing a Styles slice containing nil pointers.","commonSituations":"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.","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"],"exampleFix":"// before\n\"styles\": [ {\"id\": \"error\", ...}, null ]\n// after\n\"styles\": [ {\"id\": \"error\", \"light\": {...}, \"dark\": {...}} ]","handlingStrategy":"validation","validationCode":"const bad = (cfg.builtin?.styles ?? []).findIndex(s => s == null);\nif (bad !== -1) throw new Error(`builtin.styles[${bad}] is null`);","typeGuard":"function isBuiltinStyle(s) { return s !== null && typeof s === 'object' && typeof s.id === 'string'; }","tryCatchPattern":"if _, err := setInlineStylesData(styles, currentAV); err != nil {\n    if strings.Contains(err.Error(), \"builtin style must not be null\") { /* repair inline-styles.json and retry */ }\n    return err\n}","preventionTips":["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"],"tags":["config","json","validation","inline-styles"],"backgroundTag":"null-argument","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"}