siyuan-note/siyuan · error

must use the same fields in light and dark themes

Error message

%s must use the same fields in light and dark themes

What it means

When saving an inline style theme that supports both light and dark variants, both variants must populate the same set of fields: either both define color, or both define backgroundColor, or both define both. This validation in normalizeInlineStyleThemes rejects a pair where one variant sets a field the other omits, because rendering would have no dark-mode counterpart for a styled field.

Solutions

  1. Set the same fields on both light and dark variants: if the light theme defines color, the dark theme must also define color (and likewise for backgroundColor)
  2. If a dark value is not known, explicitly set the field to an empty string on both variants rather than defining it on only one
  3. Reorder fields so both variants consistently use color, or consistently use backgroundColor, instead of mixing

Example fix

// before
light:  {color: "#ff0000"}
dark:   {backgroundColor: "#330000"}
// after
light:  {color: "#ff0000"}
dark:   {color: "#ff5555"}
Defensive patterns

Strategy: validation

Validate before calling

function validInlineStylePair(light, dark) {
  const fields = t => (t.color ? 1 : 0) + (t.backgroundColor ? 1 : 0);
  return fields(light) > 0 && fields(light) === fields(dark);
}

Type guard

const isTheme = t => t && typeof t === "object" && typeof t.color === "string" && typeof t.backgroundColor === "string";

Prevention

When it happens

Trigger: Calling the inline style theme configuration API (e.g. saving custom style settings that pass an InlineStyleTheme pair) with e.g. light={color:'#ff0000'} and dark={backgroundColor:'#00ff00'} — one variant uses color, the other uses backgroundColor; or light defines both fields while dark defines only one.

Common situations: Hand-editing the appearance/style configuration JSON or constructing the theme payload programmatically and filling only the light variant; a frontend or plugin sending a partially filled dark theme; migrating older config that only had light colors into a format that now requires dark values.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/e89e2d72018ed01f. Report an issue: GitHub.

Appendix: source

Thrown at kernel/model/inline_style.go:807

func normalizeInlineStyleThemePair(light, dark *InlineStyleTheme, description string) (normalizedLight,
	normalizedDark *InlineStyleTheme, err error) {
	if light == nil || dark == nil {
		return nil, nil, fmt.Errorf("%s must define light and dark themes", description)
	}
	if normalizedLight, err = normalizeInlineStyleTheme(light); err != nil {
		return nil, nil, fmt.Errorf("invalid light theme of %s: %w", description, err)
	}
	if normalizedDark, err = normalizeInlineStyleTheme(dark); err != nil {
		return nil, nil, fmt.Errorf("invalid dark theme of %s: %w", description, err)
	}
	lightColor, lightBackground := normalizedLight.Color != "", normalizedLight.BackgroundColor != ""
	darkColor, darkBackground := normalizedDark.Color != "", normalizedDark.BackgroundColor != ""
	if !lightColor && !lightBackground {
		return nil, nil, fmt.Errorf("%s must define color or backgroundColor", description)
	}
	if lightColor != darkColor || lightBackground != darkBackground {
		return nil, nil, fmt.Errorf("%s must use the same fields in light and dark themes", description)
	}
	return normalizedLight, normalizedDark, nil
}

func normalizeHiddenBuiltinColorIndexes(indexes []int, field string) (ret []int, err error) {
	ret = make([]int, 0, len(indexes))
	seen := make(map[int]struct{}, len(indexes))
	maxIndex := maxBuiltinColorIndex
	if field == "av" {
		maxIndex = neutralAVColorIndex
	}
	for _, index := range indexes {
		if index < minBuiltinColorIndex || maxIndex < index {
			return nil, fmt.Errorf("hidden builtin %s index [%d] must be between %d and %d", field, index,
				minBuiltinColorIndex, maxIndex)
		}
		if _, exists := seen[index]; exists {
			continue

View on GitHub (pinned to 9f775e8a12)