siyuan-note/siyuan · error

invalid backgroundColor: %w

Error message

invalid backgroundColor: %w

What it means

Identical to the color case but for the BackgroundColor field: normalizeInlineStyleTheme validates BackgroundColor via normalizeInlineStyleColor and wraps any failure as "invalid backgroundColor: %w". A theme half may leave BackgroundColor empty (""), but a non-empty value must be a valid color.

Source

Thrown at kernel/model/inline_style.go:859

		if _, exists := seen[id]; exists {
			continue
		}
		seen[id] = struct{}{}
		ret = append(ret, id)
	}
	sort.Slice(ret, func(i, j int) bool {
		return builtinStyleOrder[ret[i]] < builtinStyleOrder[ret[j]]
	})
	return ret, nil
}

func normalizeInlineStyleTheme(theme *InlineStyleTheme) (ret *InlineStyleTheme, err error) {
	ret = &InlineStyleTheme{}
	if ret.Color, err = normalizeInlineStyleColor(theme.Color); err != nil {
		return nil, fmt.Errorf("invalid color: %w", err)
	}
	if ret.BackgroundColor, err = normalizeInlineStyleColor(theme.BackgroundColor); err != nil {
		return nil, fmt.Errorf("invalid backgroundColor: %w", err)
	}
	return ret, nil
}

func normalizeInlineStyleColor(color string) (ret string, err error) {
	ret = strings.ToLower(strings.TrimSpace(color))
	if ret == "" {
		return ret, nil
	}
	if !inlineStyleColorPattern.MatchString(ret) {
		return "", fmt.Errorf("color [%s] must use #RRGGBB format", color)
	}
	return ret, nil
}

func init() {
	av.LoadWorkspacePalette = loadWorkspaceAVPalette
}

View on GitHub (pinned to 8641553a1f)

Solutions

  1. Set BackgroundColor to "" if no background is desired, or to a valid lowercase #RRGGBB string.
  2. Convert rgba()/named colors to 6-digit hex before saving.
  3. Inspect the wrapped error to identify the exact invalid value.

Example fix

// before
theme.BackgroundColor = "rgba(0,0,0,0.5)" // rejected
// after
theme.BackgroundColor = "#000000" // or "" for none
Defensive patterns

Strategy: validation

Validate before calling

function isValidThemeBackgroundColor(c) {
  return c === "" || /^#[0-9a-fA-F]{6}$/.test(c);
}

Prevention

When it happens

Trigger: Saving an inline style theme whose light or dark half has a BackgroundColor that fails normalizeInlineStyleColor in kernel/model/inline_style.go — non-hex strings, 3-digit shorthand, or malformed values.

Common situations: Programmatic theme builders assigning CSS background values like "transparent" or "rgba(...)"; copied style strings containing trailing characters; hand-edited config JSON with malformed hex.

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/9a5ee4213ad65c79. Report an issue: GitHub.