{"record":{"id":"0755ac7091f72bee","repo":"siyuan-note/siyuan","slug":"invalid-color-w","errorCode":null,"errorMessage":"invalid color: %w","messagePattern":"invalid color: %w","errorType":"exception","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/8641553a1f07374001902d3ce773285db1292b2d/kernel/model/inline_style.go#L838-L874","documentation":"When normalizing an inline style theme (normalizeInlineStyleTheme), the Color field is passed through normalizeInlineStyleColor. If that lower-level validation fails (e.g. bad format, non-empty garbage), the error is wrapped as \"invalid color: %w\" and the whole theme is rejected. It is the color-specific half of theme validation; backgroundColor failures get their own wrapper.","triggerScenarios":"Saving an inline style theme whose light or dark half has a Color value that fails normalizeInlineStyleColor in kernel/model/inline_style.go — e.g. \"red\", \"#fff\", \"ff0000\", \"#GGHHII\", or a value with unsupported characters.","commonSituations":"Color pickers emitting rgb() or named colors instead of hex; truncated 3-digit hex codes; users typing colors into a config field; JavaScript theme generation producing uppercase or shorthand hex.","solutions":["Convert the color to a full 6-digit lowercase hex form (#RRGGBB) before saving the theme.","Expand shorthand #RGB to #RRGGBB or convert named/rgb() colors with a helper before calling the API.","Read the wrapped inner error (%w) to see the exact underlying reason and fix that value."],"exampleFix":"// before\ntheme.Color = \"#abc\" // shorthand, rejected\n// after\ntheme.Color = \"#aabbcc\" // full 6-digit hex","handlingStrategy":"validation","validationCode":"function isValidThemeColor(c) {\n  return c === \"\" || /^#[0-9a-fA-F]{6}$/.test(c);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Normalize any color input (named, rgb(), #RGB) to #RRGGBB before saving.","Run the regex check on both Color and BackgroundColor before calling the API.","Prefer a color picker component that outputs 6-digit hex."],"tags":["validation","color-format","inline-style"],"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"}