{"record":{"id":"0c4f45e155fd10ed","repo":"siyuan-note/siyuan","slug":"invalid-dark-theme-of-inline-style-s-w","errorCode":null,"errorMessage":"invalid dark theme of inline style [%s]: %w","messagePattern":"invalid dark theme of inline style \\[(.+?)\\]: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/inline_style.go","lineNumber":688,"sourceCode":"\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}\n\nfunc normalizeInlineStyleBuiltin(builtin *InlineStyleBuiltin) (ret *InlineStyleBuiltin, err error) {\n\tret = newEmptyInlineStyleBuiltin()\n\tif builtin == nil {","sourceCodeStart":670,"sourceCodeEnd":706,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/kernel/model/inline_style.go#L670-L706","documentation":"Identical to the light-theme check but applied to style.Dark: Dark.Color and Dark.BackgroundColor must each be empty or a valid #RRGGBB hex string, otherwise normalizeInlineStyleTheme fails and the error is wrapped with the style ID for the dark theme.","triggerScenarios":"setInlineStylesData or loadInlineStyles processes an InlineStyle whose Dark.Color or Dark.BackgroundColor is malformed — color names, 3-digit hex, values without '#', or out-of-range hex digits.","commonSituations":"Dark-mode colors authored by hand or copied from tools that emit rgba()/hsl() values; automation that writes dark-theme colors separately from light and formats them differently.","solutions":["Convert the dark-theme color to #RRGGBB hex format (lowercase is applied automatically).","Validate Dark colors with the same ^#[0-9a-fA-F]{6}$ check used for light colors before saving.","Fix the offending Dark color value in the on-disk inline-styles JSON."],"exampleFix":"// before\nDark: &InlineStyleTheme{BackgroundColor: \"#1e1e1eee\"} // 8-digit hex not allowed\n// after\nDark: &InlineStyleTheme{BackgroundColor: \"#1e1e1e\"}","handlingStrategy":"validation","validationCode":"const hex6 = /^#[0-9a-fA-F]{6}$/; if (theme.Color && !hex6.test(theme.Color)) throw new Error(`bad dark color ${theme.Color}`); if (theme.BackgroundColor && !hex6.test(theme.BackgroundColor)) throw new Error('bad dark backgroundColor');","typeGuard":"const isValidDarkTheme = (t: InlineStyleTheme): boolean => isValidColor(t.Color) && isValidColor(t.BackgroundColor);","tryCatchPattern":"try { await saveStyles(styles) } catch (e) { if (/invalid dark theme/.test(String(e))) { /* show the style ID and bad dark color, correct, retry */ } }","preventionTips":["Run the exact same validator on dark themes as on light themes","Do not paste rgba()/hsl() values — convert to #RRGGBB","Test dark-mode values through the same save path as light ones"],"tags":["validation","color-format","inline-styles","dark-mode"],"backgroundTag":"invalid-argument-format","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"}