{"record":{"id":"ad23240e7c535ce3","repo":"siyuan-note/siyuan","slug":"invalid-background-color-s","errorCode":null,"errorMessage":"invalid background color [%s]","messagePattern":"invalid background color \\[(.+?)\\]","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/av/color.go","lineNumber":155,"sourceCode":"\tret.Light, err = normalizeAttributeViewColorTheme(color.Light)\n\tif nil != err {\n\t\treturn nil, fmt.Errorf(\"invalid light theme of attribute view custom color [%d]: %w\", color.Index, err)\n\t}\n\tret.Dark, err = normalizeAttributeViewColorTheme(color.Dark)\n\tif nil != err {\n\t\treturn nil, fmt.Errorf(\"invalid dark theme of attribute view custom color [%d]: %w\", color.Index, err)\n\t}\n\treturn\n}\n\nfunc normalizeAttributeViewColorTheme(theme AttributeViewColorTheme) (ret AttributeViewColorTheme, err error) {\n\tret.Color = strings.ToLower(strings.TrimSpace(theme.Color))\n\tret.BackgroundColor = strings.ToLower(strings.TrimSpace(theme.BackgroundColor))\n\tif !attributeViewColorPattern.MatchString(ret.Color) {\n\t\treturn AttributeViewColorTheme{}, fmt.Errorf(\"invalid foreground color [%s]\", theme.Color)\n\t}\n\tif !attributeViewColorPattern.MatchString(ret.BackgroundColor) {\n\t\treturn AttributeViewColorTheme{}, fmt.Errorf(\"invalid background color [%s]\", theme.BackgroundColor)\n\t}\n\treturn\n}\n\n// WorkspacePalette 返回当前工作空间的数据库自定义色和混排顺序。\nfunc WorkspacePalette() (colors []*AttributeViewCustomColor, order []string) {\n\tif LoadWorkspacePalette != nil {\n\t\tcolors, order = LoadWorkspacePalette()\n\t}\n\tif nil == colors {\n\t\tcolors = []*AttributeViewCustomColor{}\n\t}\n\torder = NormalizeAttributeViewColorOrder(order, colors)\n\treturn\n}\n\n// DefaultAttributeViewColorOrder 返回内置色在前、自定义色按编号排列的默认顺序。\nfunc DefaultAttributeViewColorOrder(colors []*AttributeViewCustomColor) []string {","sourceCodeStart":137,"sourceCodeEnd":173,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/kernel/av/color.go#L137-L173","documentation":"Same validation as the foreground error, but for the theme's BackgroundColor value in an attribute view color theme. The value must match attributeViewColorPattern after trim/lowercase or the theme is rejected with the original value in the message.","triggerScenarios":"normalizeAttributeViewColorTheme invoked with a theme whose BackgroundColor fails the regex — occurs whenever custom colors are normalized via NormalizeAttributeViewCustomColors or resolveColor.","commonSituations":"Synced or hand-edited palettes with missing background values, CSS color function strings like rgba(0,0,0,.5), or uppercase/whitespace variants of otherwise-valid hex.","solutions":["Fix the background color to a valid full hex string (e.g. #1e1e1e)","Re-save the custom color through the UI so normalization is applied at write time","Validate both color fields with the library's pattern before persisting config"],"exampleFix":"// before\nbackgroundColor: \"rgba(0, 0, 0, 0.5)\"\n// after\nbackgroundColor: \"#000000\"","handlingStrategy":"validation","validationCode":"if (!/^#[0-9a-fA-F]{6}$/.test(theme.backgroundColor)) throw new Error(`invalid background color [${theme.backgroundColor}]`);","typeGuard":"function isValidBackgroundColor(t) { return typeof t?.backgroundColor === 'string' && /^#[0-9a-f]{6}$/i.test(t.backgroundColor); }","tryCatchPattern":null,"preventionTips":["Never save CSS function colors (rgba/rgb/hsl) into the palette","Validate both color and backgroundColor together before persisting","Lowercase and trim hex values at write time"],"tags":["color-validation","regex","attribute-view"],"backgroundTag":"invalid-color-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"}