siyuan-note/siyuan · error

invalid light theme of inline style

Error message

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

What it means

After the Light/Dark presence check, each theme is run through normalizeInlineStyleTheme, which validates Color and BackgroundColor strings. Any color that is non-empty must match the strict #RRGGBB hex pattern (lowercased, trimmed); otherwise the kernel wraps the failure as "invalid light theme of inline style [id]: ..." and rejects the save/load.

Solutions

  1. Convert the color to 6-digit lowercase hex form #RRGGBB before saving (e.g. rgb(255,0,0) -> #ff0000)
  2. Expand 3-digit hex (#f00 -> #ff0000) and drop any alpha component
  3. Use an empty string for "no color" rather than "none" or "transparent"
  4. Validate with a regex like ^#[0-9a-f]{6}$ in the caller before invoking the API

Example fix

// before
Light: &InlineStyleTheme{Color: "rgb(255, 0, 0)"}
// -> invalid light theme of inline style [id]: invalid color: color [...] must use #RRGGBB format
// after
Light: &InlineStyleTheme{Color: "#ff0000"}
Defensive patterns

Strategy: validation

Validate before calling

var colorRe = regexp.MustCompile(`^#[0-9a-f]{6}$`)
func validTheme(t *InlineStyleTheme) bool {
	c := strings.ToLower(strings.TrimSpace(t.Color))
	b := strings.ToLower(strings.TrimSpace(t.BackgroundColor))
	return (c == "" || colorRe.MatchString(c)) && (b == "" || colorRe.MatchString(b))
}

Type guard

func isHexColor(s string) bool {
	m, _ := regexp.MatchString(`^#[0-9a-fA-F]{6}$`, strings.TrimSpace(s))
	return m
}

Try / catch

if _, _, err := model.SetInlineStylesData(cfg); err != nil {
	if strings.Contains(err.Error(), "must use #RRGGBB format") ||
		strings.Contains(err.Error(), "invalid light theme") {
		// normalize colors to #RRGGBB and retry
	}
	return err
}

Prevention

When it happens

Trigger: Calling model.SetInlineStyles / model.SetInlineStylesData with Light.Color or Light.BackgroundColor set to values like "red", "rgb(255,0,0)", "#fff" (3-digit), "ff0000" (missing #), "#FF0000FF" (8-digit), or containing whitespace-plus-junk; loading a config written by another tool that stored CSS color names or rgba() strings.

Common situations: Taking a color from a CSS variable, browser color input, or theme file that uses rgb()/named colors; 3-digit hex shorthand from a design tool; copy-pasted hex with a stray space or uppercase is fine (trimmed/lowercased) but alpha channels are not.

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@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/c0c47bb3996a7a1f. Report an issue: GitHub.

Appendix: source

Thrown at kernel/model/inline_style.go:684

		if _, exists := ids[id]; exists {
			return nil, fmt.Errorf("duplicate inline style ID [%s]", id)
		}
		ids[id] = struct{}{}

		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
}

View on GitHub (pinned to 9f775e8a12)