{"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":"exception","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/8641553a1f07374001902d3ce773285db1292b2d/kernel/model/inline_style.go#L675-L711","documentation":"After both themes validate, the style must actually style something: at least one of Color or BackgroundColor must be non-empty in the light theme (the dark theme is checked symmetrically via the same-fields rule). A style with no colors in either field carries no visual effect and is rejected.","triggerScenarios":"setInlineStylesData receives an InlineStyle whose Light theme has both Color and BackgroundColor empty (dark likewise); loadInlineStyles reads a JSON entry with both color fields empty or absent in both themes.","commonSituations":"Creating a style entry reserved for later and saving before filling colors; a UI flow that clears both color pickers; migration tools copying style shells without theme payloads.","solutions":["Set at least Color or BackgroundColor (in both themes) before saving the style list.","Drop placeholder entries that have no colors from the list.","Fix the on-disk JSON by adding a color or removing the empty entry so loadInlineStyles succeeds."],"exampleFix":"// before\n&InlineStyle{ID: \"20240101120000-abcdefg\", Name: \"Red\",\n  Light: &InlineStyleTheme{}, Dark: &InlineStyleTheme{}}\n// after\n&InlineStyle{ID: \"20240101120000-abcdefg\", Name: \"Red\",\n  Light: &InlineStyleTheme{Color: \"#ff0000\"}, Dark: &InlineStyleTheme{Color: \"#ff0000\"}}","handlingStrategy":"validation","validationCode":"for (const s of styles) { const t = s.Light; if (!t.Color && !t.BackgroundColor) throw new Error(`style ${s.ID} has no color or backgroundColor`); }","typeGuard":"const hasVisualEffect = (t: InlineStyleTheme): boolean => t.Color !== '' || t.BackgroundColor !== '';","tryCatchPattern":"try { await saveStyles(styles) } catch (e) { if (/must define color or backgroundColor/.test(String(e))) { /* remove the empty style or set a color, then retry */ } }","preventionTips":["Do not save placeholder styles with empty themes — delete them instead","Require at least one color in the style-creation UI","Validate the full list before bulk saves"],"tags":["validation","empty-value","inline-styles","color"],"backgroundTag":"missing-required-config-field","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}