{"record":{"id":"803fcfdba2bdeff0","repo":"siyuan-note/siyuan","slug":"s-must-define-color-or-backgroundcolor","errorCode":null,"errorMessage":"%s must define color or backgroundColor","messagePattern":"(.+?) must define color or backgroundColor","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/inline_style.go","lineNumber":804,"sourceCode":"\tret.Order = av.NormalizeAttributeViewColorOrder(palette.Order, colors)\n\treturn ret, nil\n}\n\nfunc normalizeInlineStyleThemePair(light, dark *InlineStyleTheme, description string) (normalizedLight,\n\tnormalizedDark *InlineStyleTheme, err error) {\n\tif light == nil || dark == nil {\n\t\treturn nil, nil, fmt.Errorf(\"%s must define light and dark themes\", description)\n\t}\n\tif normalizedLight, err = normalizeInlineStyleTheme(light); err != nil {\n\t\treturn nil, nil, fmt.Errorf(\"invalid light theme of %s: %w\", description, err)\n\t}\n\tif normalizedDark, err = normalizeInlineStyleTheme(dark); err != nil {\n\t\treturn nil, nil, fmt.Errorf(\"invalid dark theme of %s: %w\", description, err)\n\t}\n\tlightColor, lightBackground := normalizedLight.Color != \"\", normalizedLight.BackgroundColor != \"\"\n\tdarkColor, darkBackground := normalizedDark.Color != \"\", normalizedDark.BackgroundColor != \"\"\n\tif !lightColor && !lightBackground {\n\t\treturn nil, nil, fmt.Errorf(\"%s must define color or backgroundColor\", description)\n\t}\n\tif lightColor != darkColor || lightBackground != darkBackground {\n\t\treturn nil, nil, fmt.Errorf(\"%s must use the same fields in light and dark themes\", description)\n\t}\n\treturn normalizedLight, normalizedDark, nil\n}\n\nfunc normalizeHiddenBuiltinColorIndexes(indexes []int, field string) (ret []int, err error) {\n\tret = make([]int, 0, len(indexes))\n\tseen := make(map[int]struct{}, len(indexes))\n\tmaxIndex := maxBuiltinColorIndex\n\tif field == \"av\" {\n\t\tmaxIndex = neutralAVColorIndex\n\t}\n\tfor _, index := range indexes {\n\t\tif index < minBuiltinColorIndex || maxIndex < index {\n\t\t\treturn nil, fmt.Errorf(\"hidden builtin %s index [%d] must be between %d and %d\", field, index,\n\t\t\t\tminBuiltinColorIndex, maxIndex)","sourceCodeStart":786,"sourceCodeEnd":822,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/inline_style.go#L786-L822","documentation":"After validating both themes, the normalizer requires each entry to actually define something: at least one of color or backgroundColor must be non-empty, and both themes must use the same field(s). A theme pair that is entirely empty, or that sets only color in light but only backgroundColor in dark, is rejected so light/dark rendering stays consistent.","triggerScenarios":"A builtin (or validated user) entry in inline-styles.json has light and dark objects whose color/backgroundColor are all empty strings, or light uses {color} while dark uses {backgroundColor}.","commonSituations":"Creating a placeholder entry intending to fill colors later; copying theme skeletons without values; editing one theme to add a field without updating the other; a generator emitting empty theme objects.","solutions":["Fill in at least one of color or backgroundColor in BOTH light and dark for the entry","Use the same field set in both themes (if light has color+backgroundColor, dark must too)","Remove entries that are intentionally empty instead of keeping empty shells","Reload the workspace and verify the style renders in both themes"],"exampleFix":"// before\n\"light\": {\"color\": \"#7a5c00\"}, \"dark\": {\"backgroundColor\": \"#4d3a00\"}\n// after\n\"light\": {\"color\": \"#7a5c00\", \"backgroundColor\": \"#fff3b8\"}, \"dark\": {\"color\": \"#ffd66e\", \"backgroundColor\": \"#4d3a00\"}","handlingStrategy":"validation","validationCode":"for (const entry of [...(cfg.builtin?.colors ?? []), ...(cfg.builtin?.styles ?? [])]) {\n  const fields = t => ['color', 'backgroundColor'].filter(f => t?.[f]);\n  const lf = fields(entry.light), df = fields(entry.dark);\n  if (lf.length === 0) throw new Error(`${entry.id ?? entry.index} must define color or backgroundColor`);\n  if (lf.join() !== df.join()) throw new Error(`${entry.id ?? entry.index} must use the same fields in light and dark themes`);\n}","typeGuard":"function isConsistentThemePair(e) {\n  const f = t => ['color', 'backgroundColor'].filter(k => t?.[k]);\n  return f(e.light).length > 0 && f(e.light).join() === f(e.dark).join();\n}","tryCatchPattern":"if _, err := setInlineStylesData(styles, currentAV); err != nil {\n    if strings.Contains(err.Error(), \"must define color or backgroundColor\") || strings.Contains(err.Error(), \"must use the same fields\") { /* fill/mirror fields and retry */ }\n    return err\n}","preventionTips":["Never commit empty theme shells — fill color or backgroundColor in both themes","Mirror field usage between light and dark: if light sets backgroundColor, dark must too","When adding a field to one theme, add it to the other in the same edit","Keep a small linter over inline-styles.json covering emptiness and field parity"],"tags":["config","validation","inline-styles","theme"],"backgroundTag":"schema-validation-failed","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"}