{"record":{"id":"ec6f6466e6fecea9","repo":"siyuan-note/siyuan","slug":"inline-style-s-must-define-color-or-backgroundc","errorCode":null,"errorMessage":"inline style [%s] must define color or backgroundColor","messagePattern":"inline style \\[(.+?)\\] must define color or backgroundColor","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/inline_style.go","lineNumber":693,"sourceCode":"\t\tif maxInlineStyleNameRunes < utf8.RuneCountInString(name) {\n\t\t\treturn nil, fmt.Errorf(\"inline style name exceeds the %d character limit\", maxInlineStyleNameRunes)\n\t\t}\n\t\tif style.Light == nil || style.Dark == nil {\n\t\t\treturn nil, fmt.Errorf(\"inline style [%s] must define light and dark themes\", id)\n\t\t}\n\n\t\tlight, err := normalizeInlineStyleTheme(style.Light)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"invalid light theme of inline style [%s]: %w\", id, err)\n\t\t}\n\t\tdark, err := normalizeInlineStyleTheme(style.Dark)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"invalid dark theme of inline style [%s]: %w\", id, err)\n\t\t}\n\t\tlightColor, lightBackground := light.Color != \"\", light.BackgroundColor != \"\"\n\t\tdarkColor, darkBackground := dark.Color != \"\", dark.BackgroundColor != \"\"\n\t\tif !lightColor && !lightBackground {\n\t\t\treturn nil, fmt.Errorf(\"inline style [%s] must define color or backgroundColor\", id)\n\t\t}\n\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 {","sourceCodeStart":675,"sourceCodeEnd":711,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/inline_style.go#L675-L711","documentation":"A theme pair where the light theme has neither Color nor BackgroundColor (both empty after normalization) is inert — it would render nothing. normalizeInlineStyles rejects such a style and aborts the whole save/load, requiring at least one visual property.","triggerScenarios":"Calling model.SetInlineStyles / model.SetInlineStylesData with &InlineStyle{Light: &InlineStyleTheme{}, Dark: &InlineStyleTheme{...}} — both light fields empty; a style built from UI state where the user cleared both light inputs; JSON config with empty light color fields (e.g. after a bad merge); passing themes that only set non-support fields (Hidden, Name) and no color.","commonSituations":"A \"reset/clear\" action blanking the light theme while dark keeps values; form submission before the color picker commits; external tools exporting styles that legitimately have no light variant (not allowed here).","solutions":["Set at least Color or BackgroundColor on the light theme (and mirror the same field on dark)","If the style is meant to be disabled, remove it from the list entirely rather than emptying its light theme","Validate the light theme has one non-empty color field before calling the API","Repair the config JSON so the entry has a real light color"],"exampleFix":"// before\nLight: &InlineStyleTheme{}, Dark: &InlineStyleTheme{Color: \"#eee\"}\n// -> inline style [id] must define color or backgroundColor\n// after\nLight: &InlineStyleTheme{Color: \"#111\"}, Dark: &InlineStyleTheme{Color: \"#eee\"}","handlingStrategy":"validation","validationCode":"func lightThemeHasVisual(t *InlineStyleTheme) bool {\n\treturn strings.TrimSpace(t.Color) != \"\" || strings.TrimSpace(t.BackgroundColor) != \"\"\n}","typeGuard":"func hasVisual(theme *InlineStyleTheme) bool {\n\treturn theme != nil && (theme.Color != \"\" || theme.BackgroundColor != \"\")\n}","tryCatchPattern":"if _, _, err := model.SetInlineStyles(styles); err != nil {\n\tif strings.Contains(err.Error(), \"must define color or backgroundColor\") {\n\t\t// drop or complete the empty style, then retry\n\t}\n\treturn err\n}","preventionTips":["Require at least one color in the style editor before enabling Save","Treat \"clear color in both themes\" as a delete action, not an update","Check the trimmed values, since whitespace is stripped before validation"],"tags":["go","validation","required-field","themes"],"backgroundTag":"missing-required-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"}