{"record":{"id":"c0c47bb3996a7a1f","repo":"siyuan-note/siyuan","slug":"invalid-light-theme-of-inline-style-s-w","errorCode":null,"errorMessage":"invalid light theme of inline style [%s]: %w","messagePattern":"invalid light theme of inline style \\[(.+?)\\]: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/inline_style.go","lineNumber":684,"sourceCode":"\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}\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}","sourceCodeStart":666,"sourceCodeEnd":702,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/inline_style.go#L666-L702","documentation":"After the Light/Dark presence check, each theme is run through normalizeInlineStyleTheme, which validates Color and BackgroundColor strings. Any color that is non-empty must match the strict #RRGGBB hex pattern (lowercased, trimmed); otherwise the kernel wraps the failure as \"invalid light theme of inline style [id]: ...\" and rejects the save/load.","triggerScenarios":"Calling model.SetInlineStyles / model.SetInlineStylesData with Light.Color or Light.BackgroundColor set to values like \"red\", \"rgb(255,0,0)\", \"#fff\" (3-digit), \"ff0000\" (missing #), \"#FF0000FF\" (8-digit), or containing whitespace-plus-junk; loading a config written by another tool that stored CSS color names or rgba() strings.","commonSituations":"Taking a color from a CSS variable, browser color input, or theme file that uses rgb()/named colors; 3-digit hex shorthand from a design tool; copy-pasted hex with a stray space or uppercase is fine (trimmed/lowercased) but alpha channels are not.","solutions":["Convert the color to 6-digit lowercase hex form #RRGGBB before saving (e.g. rgb(255,0,0) -> #ff0000)","Expand 3-digit hex (#f00 -> #ff0000) and drop any alpha component","Use an empty string for \"no color\" rather than \"none\" or \"transparent\"","Validate with a regex like ^#[0-9a-f]{6}$ in the caller before invoking the API"],"exampleFix":"// before\nLight: &InlineStyleTheme{Color: \"rgb(255, 0, 0)\"}\n// -> invalid light theme of inline style [id]: invalid color: color [...] must use #RRGGBB format\n// after\nLight: &InlineStyleTheme{Color: \"#ff0000\"}","handlingStrategy":"validation","validationCode":"var colorRe = regexp.MustCompile(`^#[0-9a-f]{6}$`)\nfunc validTheme(t *InlineStyleTheme) bool {\n\tc := strings.ToLower(strings.TrimSpace(t.Color))\n\tb := strings.ToLower(strings.TrimSpace(t.BackgroundColor))\n\treturn (c == \"\" || colorRe.MatchString(c)) && (b == \"\" || colorRe.MatchString(b))\n}","typeGuard":"func isHexColor(s string) bool {\n\tm, _ := regexp.MatchString(`^#[0-9a-fA-F]{6}$`, strings.TrimSpace(s))\n\treturn m\n}","tryCatchPattern":"if _, _, err := model.SetInlineStylesData(cfg); err != nil {\n\tif strings.Contains(err.Error(), \"must use #RRGGBB format\") ||\n\t\tstrings.Contains(err.Error(), \"invalid light theme\") {\n\t\t// normalize colors to #RRGGBB and retry\n\t}\n\treturn err\n}","preventionTips":["Convert any CSS color (named, rgb(), rgba(), 3-digit hex) to #RRGGBB before saving","Use \"\" to mean \"unset\", never \"none\" or \"transparent\"","Run one shared color-normalization helper for both light and dark themes"],"tags":["go","validation","color-format","inline-styles"],"backgroundTag":"invalid-argument-format","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"}