{"record":{"id":"93228dffc6f4efd3","repo":"siyuan-note/siyuan","slug":"invalid-foreground-color-s","errorCode":null,"errorMessage":"invalid foreground color [%s]","messagePattern":"invalid foreground color \\[(.+?)\\]","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/av/color.go","lineNumber":152,"sourceCode":"\t}\n\n\tret = &AttributeViewCustomColor{Index: color.Index, Hidden: color.Hidden}\n\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}","sourceCodeStart":134,"sourceCodeEnd":170,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/av/color.go#L134-L170","documentation":"normalizeAttributeViewColorTheme requires the theme's foreground Color to match attributeViewColorPattern (hex color form) after lowercasing and trimming. Non-matching values are rejected with this error quoting the original input.","triggerScenarios":"Calling normalizeAttributeViewCustomColor (directly or via NormalizeAttributeViewCustomColors/resolveColor) with theme.Color like \"\", \"red\", \"rgb(255,0,0)\", or a malformed hex string.","commonSituations":"CSS color names or functional notations pasted into palette settings; truncated hex values; locale-dependent input with stray whitespace (whitespace is trimmed, but the value must still be hex).","solutions":["Convert the color to #rgb or #rrggbb hex form before saving","Use a color picker that emits hex values","Check the pattern in kernel/av/color.go to confirm the accepted format"],"exampleFix":"// before\nTheme{Color: \"rgb(255, 0, 0)\"}\n// after\nTheme{Color: \"#ff0000\"}","handlingStrategy":"validation","validationCode":"var colorRe = regexp.MustCompile(`^#[0-9a-f]{3}([0-9a-f]{3})?$`)\nfunc validHex(s string) bool { return colorRe.MatchString(strings.ToLower(strings.TrimSpace(s))) }","typeGuard":null,"tryCatchPattern":"if _, err := av.NormalizeAttributeViewCustomColors(colors, true); err != nil {\n    if strings.Contains(err.Error(), \"invalid foreground color\") { convertToHex(colors) }\n}","preventionTips":["Use color pickers that emit hex strings","Convert CSS names and rgb() notation to hex upstream","Trim and lowercase before validating to match kernel normalization"],"tags":["attribute-view","color","format"],"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"}