{"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/8641553a1f07374001902d3ce773285db1292b2d/kernel/av/color.go#L134-L170","documentation":"normalizeAttributeViewColorTheme validates a color theme's foreground (Color) value against attributeViewColorPattern after trimming and lowercasing. If it does not match, the original (untrimmed) value is reported in the error. This guards the attribute view custom palette against malformed colors.","triggerScenarios":"Any call path into normalizeAttributeViewCustomColor (hence NormalizeAttributeViewCustomColors / resolveColor) where theme.Color is not matched by the color regex — e.g. empty string, named colors, non-hex values.","commonSituations":"Importing a database or config JSON with colors produced by another tool; typos like 'ff0000' (missing '#') or '#fff' (3-digit shorthand not allowed by the pattern).","solutions":["Correct the foreground color to the exact format the pattern expects (typically full hex like #aabbcc)","Trim whitespace and lowercase the value before passing it in, though trimming is already applied internally — ensure the raw format is right","Pre-validate color strings client-side with the same regex before persisting"],"exampleFix":"// before\ntheme.Color = \"#FFF\"\n// after\ntheme.Color = \"#ffffff\"","handlingStrategy":"validation","validationCode":"if (!/^#[0-9a-fA-F]{6}$/.test(theme.color)) throw new Error(`invalid foreground color [${theme.color}]`);","typeGuard":"function isValidForegroundColor(t) { return typeof t?.color === 'string' && /^#[0-9a-f]{6}$/i.test(t.color); }","tryCatchPattern":null,"preventionTips":["Use a color picker that emits full hex values","Expand shorthand #fff to #ffffff before persisting","Run palette normalization in CI on config changes"],"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-14T05:17:10.506Z"}