{"record":{"id":"0755ac7091f72bee","repo":"siyuan-note/siyuan","slug":"invalid-color-w","errorCode":null,"errorMessage":"invalid color: %w","messagePattern":"invalid color: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/inline_style.go","lineNumber":856,"sourceCode":"\t\tif _, valid := builtinStyleOrder[id]; !valid {\n\t\t\treturn nil, fmt.Errorf(\"invalid hidden builtin style ID [%s]\", id)\n\t\t}\n\t\tif _, exists := seen[id]; exists {\n\t\t\tcontinue\n\t\t}\n\t\tseen[id] = struct{}{}\n\t\tret = append(ret, id)\n\t}\n\tsort.Slice(ret, func(i, j int) bool {\n\t\treturn builtinStyleOrder[ret[i]] < builtinStyleOrder[ret[j]]\n\t})\n\treturn ret, nil\n}\n\nfunc normalizeInlineStyleTheme(theme *InlineStyleTheme) (ret *InlineStyleTheme, err error) {\n\tret = &InlineStyleTheme{}\n\tif ret.Color, err = normalizeInlineStyleColor(theme.Color); err != nil {\n\t\treturn nil, fmt.Errorf(\"invalid color: %w\", err)\n\t}\n\tif ret.BackgroundColor, err = normalizeInlineStyleColor(theme.BackgroundColor); err != nil {\n\t\treturn nil, fmt.Errorf(\"invalid backgroundColor: %w\", err)\n\t}\n\treturn ret, nil\n}\n\nfunc normalizeInlineStyleColor(color string) (ret string, err error) {\n\tret = strings.ToLower(strings.TrimSpace(color))\n\tif ret == \"\" {\n\t\treturn ret, nil\n\t}\n\tif !inlineStyleColorPattern.MatchString(ret) {\n\t\treturn \"\", fmt.Errorf(\"color [%s] must use #RRGGBB format\", color)\n\t}\n\treturn ret, nil\n}\n","sourceCodeStart":838,"sourceCodeEnd":874,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/inline_style.go#L838-L874","documentation":"normalizeInlineStyleTheme validates a theme's Color via normalizeInlineStyleColor and wraps any failure with \"invalid color\". This means the color string supplied for the light or dark variant failed normalization — it was non-empty but not a well-formed color value (e.g. not #RRGGBB).","triggerScenarios":"Saving an inline style theme (light or dark variant) whose color field is a malformed value such as \"red\", \"#fff\", \"ff0000\", or \"#GGHHII\"; the underlying normalizeInlineStyleColor error is wrapped and surfaced with this message.","commonSituations":"Hand-editing theme config with CSS color names or 3-digit hex; copying colors from design tools that emit rgb() or 8-digit hex; plugin code building color strings without validation.","solutions":["Convert the value to 6-digit hex form like #RRGGBB (e.g. red -> #ff0000, #fff -> #ffffff)","Convert rgb()/rgba() values to hex before saving, or clear the field to an empty string to remove the color","Validate with a regex ^#[0-9a-fA-F]{6}$ in client code before submitting"],"exampleFix":"// before\ncolor: \"#fff\"\n// after\ncolor: \"#ffffff\"","handlingStrategy":"validation","validationCode":"const HEX6 = /^#[0-9a-fA-F]{6}$/;\nfunction validColor(c) { return c === \"\" || HEX6.test(c.trim()); }","typeGuard":"const isHexColor = v => typeof v === \"string\" && /^#[0-9a-fA-F]{6}$/.test(v.trim());","tryCatchPattern":"try { saveTheme(t); } catch (e) { if (String(e).includes(\"invalid color\")) { t.color = \"\"; saveTheme(t); } }","preventionTips":["Normalize all colors to #RRGGBB at input time","Reject CSS names, rgb(), and 3-digit hex in your form validation","Use empty string to represent 'no color'"],"tags":["validation","color","inline-style","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"}