{"record":{"id":"959e59e64e7828cb","repo":"siyuan-note/siyuan","slug":"builtin-color-must-not-be-null","errorCode":null,"errorMessage":"builtin color must not be null","messagePattern":"builtin color must not be null","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/inline_style.go","lineNumber":713,"sourceCode":"\t\tif lightColor != darkColor || lightBackground != darkBackground {\n\t\t\treturn nil, fmt.Errorf(\"inline style [%s] must use the same fields in light and dark themes\", id)\n\t\t}\n\n\t\tret = append(ret, &InlineStyle{ID: id, Name: name, Hidden: style.Hidden, Light: light, Dark: dark})\n\t}\n\treturn ret, nil\n}\n\nfunc normalizeInlineStyleBuiltin(builtin *InlineStyleBuiltin) (ret *InlineStyleBuiltin, err error) {\n\tret = newEmptyInlineStyleBuiltin()\n\tif builtin == nil {\n\t\treturn ret, nil\n\t}\n\n\tcolorIndexes := make(map[int]struct{}, len(builtin.Colors))\n\tfor _, color := range builtin.Colors {\n\t\tif color == nil {\n\t\t\treturn nil, errors.New(\"builtin color must not be null\")\n\t\t}\n\t\tif color.Index < minBuiltinColorIndex || neutralAVColorIndex < color.Index {\n\t\t\treturn nil, fmt.Errorf(\"builtin color index [%d] must be between %d and %d\", color.Index,\n\t\t\t\tminBuiltinColorIndex, neutralAVColorIndex)\n\t\t}\n\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","sourceCodeStart":695,"sourceCodeEnd":731,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/inline_style.go#L695-L731","documentation":"normalizeInlineStyleBuiltin validates the builtin section of /storage/inline-styles.json before it is used. It rejects any entry in builtin.colors that deserialized to nil (an explicit JSON null element in the colors array). The library refuses to continue rather than later dereference a nil color struct.","triggerScenarios":"Calling setInlineStylesData or loadInlineStyles when the workspace inline-styles.json contains `\"colors\": [null, ...]` under builtin, or when Go code passes an InlineStyleBuiltin whose Colors slice holds a nil *InlineStyleBuiltinColor.","commonSituations":"Hand-edited or externally synced inline-styles.json with a stray null element; a sync merge tool or script rewriting the JSON and emitting null placeholders; a buggy generator that appends a zero-value entry.","solutions":["Open /storage/inline-styles.json in the workspace and remove the null element from builtin.colors","Validate the JSON with a schema/linter (each colors entry needs index, light, dark) before writing it back","If the file was corrupted by sync, stop sync, restore a known-good copy of inline-styles.json, then resync","If produced by code, ensure every element appended to Colors is a non-nil &InlineStyleBuiltinColor{...}"],"exampleFix":"// before (inline-styles.json)\n\"builtin\": { \"colors\": [ {\"index\": 1, ...}, null ] }\n// after\n\"builtin\": { \"colors\": [ {\"index\": 1, \"light\": {...}, \"dark\": {...}} ] }","handlingStrategy":"validation","validationCode":"const cfg = JSON.parse(await fs.readFile('/workspace/storage/inline-styles.json', 'utf8'));\nconst bad = (cfg.builtin?.colors ?? []).findIndex(c => c == null);\nif (bad !== -1) throw new Error(`builtin.colors[${bad}] is null`);","typeGuard":"function isBuiltinColor(c) { return c !== null && typeof c === 'object' && Number.isInteger(c.index); }","tryCatchPattern":"try { styles = loadInlineStyles(); } catch (err) { if (strings.Contains(err.Error(), \"builtin color must not be null\")) { /* restore inline-styles.json from backup, then retry */ } return err; }","preventionTips":["Never hand-edit inline-styles.json without validating afterwards","Use the in-app settings UI or API to modify builtin colors instead of editing the file","Run a JSON schema check (non-null array elements) before saving or syncing the file","Back up inline-styles.json before sync operations that may merge it"],"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"}