{"record":{"id":"5f759c43988b8d19","repo":"siyuan-note/siyuan","slug":"inline-style-s-must-define-light-and-dark-theme","errorCode":null,"errorMessage":"inline style [%s] must define light and dark themes","messagePattern":"inline style \\[(.+?)\\] must define light and dark themes","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/inline_style.go","lineNumber":679,"sourceCode":"\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{}{}\n\n\t\tname := strings.TrimSpace(style.Name)\n\t\tif name == \"\" {\n\t\t\treturn nil, errors.New(\"inline style name must not be empty\")\n\t\t}\n\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}","sourceCodeStart":661,"sourceCodeEnd":697,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/inline_style.go#L661-L697","documentation":"A custom inline style must always provide both a Light and a Dark InlineStyleTheme; a single-theme definition cannot render consistently when the user switches appearance modes. normalizeInlineStyles checks both pointers and rejects the whole save/load if either is nil.","triggerScenarios":"Calling model.SetInlineStyles / model.SetInlineStylesData with &InlineStyle{ID:..., Name:..., Light: l} and Dark left nil (or vice versa); JSON config where the dark object was deleted or the field name misspelled so it unmarshals to nil; code constructing themes conditionally and skipping the dark variant.","commonSituations":"Saving a style while the app is in light mode and code only fills the visible theme; hand-edited JSON dropping \"dark\"; an external migration tool copying only one theme; Go composite literals omitting the Dark field by mistake.","solutions":["Always populate both Light and Dark, using the same color for both if no dark variant is wanted","Mirror the light theme into dark when a distinct dark palette is not needed: Dark: light","Fix the config JSON so each style has both light and dark objects","In builders, require both themes as parameters so the compiler prevents one-sided construction"],"exampleFix":"// before\n&InlineStyle{ID: id, Name: n, Light: &InlineStyleTheme{Color: \"#ff0000\"}} // Dark nil\n// after\n&InlineStyle{ID: id, Name: n,\n  Light: &InlineStyleTheme{Color: \"#ff0000\"},\n  Dark:  &InlineStyleTheme{Color: \"#ff0000\"}}","handlingStrategy":"validation","validationCode":"func hasBothThemes(s *InlineStyle) bool { return s.Light != nil && s.Dark != nil }","typeGuard":"func completeStyle(s *InlineStyle) bool {\n\treturn s != nil && s.Light != nil && s.Dark != nil\n}","tryCatchPattern":"if _, _, err := model.SetInlineStyles(styles); err != nil {\n\tif strings.Contains(err.Error(), \"must define light and dark themes\") {\n\t\t// clone the present theme into the missing one and retry\n\t}\n\treturn err\n}","preventionTips":["Construct styles via a helper that takes both themes as required parameters","Mirror the light theme into Dark when no distinct dark palette exists","Never build InlineStyle literals that omit the Dark field"],"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"}