{"record":{"id":"7e5641872e211024","repo":"siyuan-note/siyuan","slug":"inline-style-must-not-be-null","errorCode":null,"errorMessage":"inline style must not be null","messagePattern":"inline style must not be null","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/inline_style.go","lineNumber":651,"sourceCode":"\t\tif _, ok := hidden[index]; !ok {\n\t\t\tret = append(ret, index)\n\t\t}\n\t}\n\tif len(ret) == 0 {\n\t\treturn []int{neutralAVColorIndex}\n\t}\n\treturn ret\n}\n\nfunc normalizeInlineStyles(styles []*InlineStyle, generateIDs bool) (ret []*InlineStyle, err error) {\n\tif maxInlineStyles < len(styles) {\n\t\treturn nil, fmt.Errorf(\"inline styles count exceeds the %d item limit\", maxInlineStyles)\n\t}\n\tret = make([]*InlineStyle, 0, len(styles))\n\tids := make(map[string]struct{}, len(styles))\n\tfor _, style := range styles {\n\t\tif style == nil {\n\t\t\treturn nil, errors.New(\"inline style must not be null\")\n\t\t}\n\n\t\tid := strings.TrimSpace(style.ID)\n\t\tif id == \"\" && generateIDs {\n\t\t\tfor {\n\t\t\t\tid = ast.NewNodeID()\n\t\t\t\tif _, exists := ids[id]; !exists {\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif !ast.IsNodeIDPattern(id) {\n\t\t\treturn nil, fmt.Errorf(\"invalid inline style ID [%s]\", id)\n\t\t}\n\t\tif _, exists := ids[id]; exists {\n\t\t\treturn nil, fmt.Errorf(\"duplicate inline style ID [%s]\", id)\n\t\t}\n\t\tids[id] = struct{}{}","sourceCodeStart":633,"sourceCodeEnd":669,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/inline_style.go#L633-L669","documentation":"normalizeInlineStyles validates every element of the custom inline style list passed to setInlineStylesData (backing SetInlineStyles, SetInlineStylesData, SetWorkspaceAVPalette) and loadInlineStyles. A nil *InlineStyle element in the slice cannot carry an ID, name, or themes, so the kernel rejects the whole list before any normalization or persistence occurs. The save is aborted atomically: nothing is written to the inline styles JSON.","triggerScenarios":"Passing a []*InlineStyle containing a nil element to model.SetInlineStyles or model.SetInlineStylesData; decoding the styles JSON where a styles[] entry is JSON null; building the slice programmatically with a placeholder nil slot left in place; loadInlineStyles reading a hand-edited or partially written inline styles config file that contains a null array entry.","commonSituations":"Frontend/automation code appending a new style by pushing to an array that still contains an uninitialized entry; JSON unmarshalling of a config where a null literal was left in the styles array after manual editing; Go code doing `styles := make([]*InlineStyle, n)` and filling only some indices.","solutions":["Remove the nil element from the []*InlineStyle slice before calling SetInlineStyles / SetInlineStylesData","When constructing the slice, use append instead of pre-sized make() so no nil slots remain","Fix the inline styles JSON on disk (remove the null array entry) if the error comes from loadInlineStyles","Iterate the incoming array and skip-or-fail null entries in the caller before invoking the API"],"exampleFix":"// before\nstyles := make([]*InlineStyle, 3)\nstyles[0] = s1; styles[2] = s3 // styles[1] is nil\nSetInlineStyles(styles) // -> \"inline style must not be null\"\n// after\nstyles := []*InlineStyle{s1, s2, s3} // all entries non-nil\nSetInlineStyles(styles)","handlingStrategy":"validation","validationCode":"func hasNoNilStyles(styles []*InlineStyle) bool {\n\tfor _, s := range styles {\n\t\tif s == nil {\n\t\t\treturn false\n\t\t}\n\t}\n\treturn true\n}","typeGuard":"func validStyle(s *InlineStyle) bool { return s != nil }","tryCatchPattern":"ret, _, err := model.SetInlineStyles(styles)\nif err != nil {\n\tif strings.Contains(err.Error(), \"must not be null\") {\n\t\t// sanitize: drop nil entries and retry once\n\t}\n\treturn err\n}","preventionTips":["Use append to build style slices instead of pre-sized make()","Sanitize any slice decoded from JSON before saving","Never insert placeholder nil entries into persisted arrays"],"tags":["go","validation","inline-styles","null-value"],"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"}