siyuan-note/siyuan · error

invalid dark theme of inline style [%s]: %w

Error message

invalid dark theme of inline style [%s]: %w

What it means

Identical to the light-theme check but applied to style.Dark: Dark.Color and Dark.BackgroundColor must each be empty or a valid #RRGGBB hex string, otherwise normalizeInlineStyleTheme fails and the error is wrapped with the style ID for the dark theme.

Source

Thrown at kernel/model/inline_style.go:688

		name := strings.TrimSpace(style.Name)
		if name == "" {
			return nil, errors.New("inline style name must not be empty")
		}
		if maxInlineStyleNameRunes < utf8.RuneCountInString(name) {
			return nil, fmt.Errorf("inline style name exceeds the %d character limit", maxInlineStyleNameRunes)
		}
		if style.Light == nil || style.Dark == nil {
			return nil, fmt.Errorf("inline style [%s] must define light and dark themes", id)
		}

		light, err := normalizeInlineStyleTheme(style.Light)
		if err != nil {
			return nil, fmt.Errorf("invalid light theme of inline style [%s]: %w", id, err)
		}
		dark, err := normalizeInlineStyleTheme(style.Dark)
		if err != nil {
			return nil, fmt.Errorf("invalid dark theme of inline style [%s]: %w", id, err)
		}
		lightColor, lightBackground := light.Color != "", light.BackgroundColor != ""
		darkColor, darkBackground := dark.Color != "", dark.BackgroundColor != ""
		if !lightColor && !lightBackground {
			return nil, fmt.Errorf("inline style [%s] must define color or backgroundColor", id)
		}
		if lightColor != darkColor || lightBackground != darkBackground {
			return nil, fmt.Errorf("inline style [%s] must use the same fields in light and dark themes", id)
		}

		ret = append(ret, &InlineStyle{ID: id, Name: name, Hidden: style.Hidden, Light: light, Dark: dark})
	}
	return ret, nil
}

func normalizeInlineStyleBuiltin(builtin *InlineStyleBuiltin) (ret *InlineStyleBuiltin, err error) {
	ret = newEmptyInlineStyleBuiltin()
	if builtin == nil {

View on GitHub (pinned to 8641553a1f)

Solutions

  1. Convert the dark-theme color to #RRGGBB hex format (lowercase is applied automatically).
  2. Validate Dark colors with the same ^#[0-9a-fA-F]{6}$ check used for light colors before saving.
  3. Fix the offending Dark color value in the on-disk inline-styles JSON.

Example fix

// before
Dark: &InlineStyleTheme{BackgroundColor: "#1e1e1eee"} // 8-digit hex not allowed
// after
Dark: &InlineStyleTheme{BackgroundColor: "#1e1e1e"}
Defensive patterns

Strategy: validation

Validate before calling

const hex6 = /^#[0-9a-fA-F]{6}$/; if (theme.Color && !hex6.test(theme.Color)) throw new Error(`bad dark color ${theme.Color}`); if (theme.BackgroundColor && !hex6.test(theme.BackgroundColor)) throw new Error('bad dark backgroundColor');

Type guard

const isValidDarkTheme = (t: InlineStyleTheme): boolean => isValidColor(t.Color) && isValidColor(t.BackgroundColor);

Try / catch

try { await saveStyles(styles) } catch (e) { if (/invalid dark theme/.test(String(e))) { /* show the style ID and bad dark color, correct, retry */ } }

Prevention

When it happens

Trigger: setInlineStylesData or loadInlineStyles processes an InlineStyle whose Dark.Color or Dark.BackgroundColor is malformed — color names, 3-digit hex, values without '#', or out-of-range hex digits.

Common situations: Dark-mode colors authored by hand or copied from tools that emit rgba()/hsl() values; automation that writes dark-theme colors separately from light and formats them differently.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@8641553a1f (2026-09-11). Data as JSON: /api/errors/0c4f45e155fd10ed. Report an issue: GitHub.