earendil-works/pi · error

Invalid color value

Error message

Invalid color value: ${color}

What it means

Value validation in fgAnsi/bgAnsi: the color value is neither an empty string, a 256-color index number, nor a '#'-prefixed hex, so it cannot be rendered as an ANSI color. Usually a misspelled variable reference or stray literal in a theme.

Solutions

  1. Use '#rrggbb', a palette index number, or '' for default
  2. If it references a variable, drop stray characters so it matches a defined var name
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at packages/coding-agent/src/modes/interactive/theme/theme.ts:285 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of earendil-works/pi@4af9d21d3b (2026-08-24). Data as JSON: /api/errors/7ca9a53e4caabee7. Report an issue: GitHub.

Appendix: source

Thrown at packages/coding-agent/src/modes/interactive/theme/theme.ts:285

function hexTo256(hex: string): number {
	const { r, g, b } = hexToRgb(hex);
	return rgbTo256(r, g, b);
}

function fgAnsi(color: string | number, mode: ColorMode): string {
	if (color === "") return "\x1b[39m";
	if (typeof color === "number") return `\x1b[38;5;${color}m`;
	if (color.startsWith("#")) {
		if (mode === "truecolor") {
			const { r, g, b } = hexToRgb(color);
			return `\x1b[38;2;${r};${g};${b}m`;
		} else {
			const index = hexTo256(color);
			return `\x1b[38;5;${index}m`;
		}
	}
	throw new Error(`Invalid color value: ${color}`);
}

function bgAnsi(color: string | number, mode: ColorMode): string {
	if (color === "") return "\x1b[49m";
	if (typeof color === "number") return `\x1b[48;5;${color}m`;
	if (color.startsWith("#")) {
		if (mode === "truecolor") {
			const { r, g, b } = hexToRgb(color);
			return `\x1b[48;2;${r};${g};${b}m`;
		} else {
			const index = hexTo256(color);
			return `\x1b[48;5;${index}m`;
		}
	}
	throw new Error(`Invalid color value: ${color}`);
}

function resolveVarRefs(

View on GitHub (pinned to 4af9d21d3b)