{"record":{"id":"233d920b35669b5f","repo":"siyuan-note/siyuan","slug":"inline-styles-must-not-be-null","errorCode":null,"errorMessage":"inline styles must not be null","messagePattern":"inline styles must not be null","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/inline_style.go","lineNumber":231,"sourceCode":"\t\t\t})\n\t\t}\n\t\tfilteredHidden := current.Builtin.Hidden.AV[:0]\n\t\tfor _, index := range current.Builtin.Hidden.AV {\n\t\t\tif index != patch.Index {\n\t\t\t\tfilteredHidden = append(filteredHidden, index)\n\t\t\t}\n\t\t}\n\t\tcurrent.Builtin.Hidden.AV = filteredHidden\n\t\tif patch.Hidden {\n\t\t\tcurrent.Builtin.Hidden.AV = append(current.Builtin.Hidden.AV, patch.Index)\n\t\t}\n\t}\n\treturn setInlineStylesData(current, currentAV)\n}\n\nfunc setInlineStylesData(styles *InlineStyles, currentAV *InlineStyleAV) (ret *InlineStyles, changed bool, err error) {\n\tif styles == nil {\n\t\treturn nil, false, errors.New(\"inline styles must not be null\")\n\t}\n\tif styles.Version != InlineStylesVersion {\n\t\treturn nil, false, fmt.Errorf(\"unsupported inline styles version [%d]\", styles.Version)\n\t}\n\tif currentAV == nil {\n\t\tcurrentAV = newEmptyInlineStyleAV()\n\t}\n\n\tnormalizedStyles, err := normalizeInlineStyles(styles.Styles, true)\n\tif err != nil {\n\t\treturn nil, false, err\n\t}\n\tnormalizedBuiltin, err := normalizeInlineStyleBuiltin(styles.Builtin)\n\tif err != nil {\n\t\treturn nil, false, err\n\t}\n\tnormalizedAV, err := normalizeInlineStyleAV(styles.AV, true)\n\tif err != nil {","sourceCodeStart":213,"sourceCodeEnd":249,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/kernel/model/inline_style.go#L213-L249","documentation":"setInlineStylesData is the single write path for the workspace inline-styles file (custom AV color palettes). It refuses a nil styles pointer because there is nothing to normalize, version-check, merge, or persist. The error is a caller-contract violation: callers (SetInlineStyles, SetInlineStylesData, SetWorkspaceAVPalette via replaceWorkspaceAVPalette) must pass a decoded InlineStyles value.","triggerScenarios":"Calling SetInlineStyles/SetInlineStylesData with a nil *InlineStyles, or an upstream JSON decode of the inline-styles file that yields nil (e.g. empty or 'null' file content decoded into a nil pointer) then passed back into the setter.","commonSituations":"Hand-editing or truncating storage/inline_styles (JSON 'null'/empty) and then triggering a palette update; a plugin or integration calling the API with an unset styles object; migration code that decodes old data into a nil struct.","solutions":["Ensure the caller constructs a valid *InlineStyles (at least an empty struct with Version = InlineStylesVersion) before calling","If loading from disk, treat null/empty file content as newEmptyInlineStyleAV()/default styles instead of passing nil","Decode into a non-pointer-initialized value and only call the setter when decoding succeeded","Wrap the call and surface the error to the user instead of retrying with the same nil value"],"exampleFix":"// before\nvar styles *InlineStyles\nret, changed, err := SetInlineStyles(styles) // panics into error: inline styles must not be null\n// after\nstyles := &InlineStyles{Version: InlineStylesVersion, Styles: map[string]*InlineStyle{}}\nret, changed, err := SetInlineStyles(styles)","handlingStrategy":"type-guard","validationCode":"if styles == nil {\n    styles = &InlineStyles{Version: InlineStylesVersion}\n}\nret, changed, err := model.SetInlineStyles(styles)","typeGuard":"func validStyles(s *model.InlineStyles) bool { return s != nil && s.Version == model.InlineStylesVersion }","tryCatchPattern":"ret, changed, err := model.SetInlineStyles(styles)\nif err != nil && strings.Contains(err.Error(), \"must not be null\") {\n    styles = &model.InlineStyles{Version: model.InlineStylesVersion}\n    ret, changed, err = model.SetInlineStyles(styles)\n}","preventionTips":["Never pass a decoded-but-nil pointer straight into SetInlineStyles; initialize defaults on decode failure","Treat an empty or 'null' styles file as a fresh palette, not nil","Centralize styles loading in one helper that always returns a non-nil value"],"tags":["go","null-argument","validation","attribute-view"],"backgroundTag":"null-argument","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}