rouge-ruby/rouge · error · RuntimeError
invalid color: #{color}
Error message
invalid color: #{color} What it means
Error "invalid color: #{color}" thrown in rouge-ruby/rouge.
Source
Thrown at lib/rouge/formatters/terminal256.rb:138
def escape(attrs)
return '' if attrs.empty?
"\e[#{attrs.join(';')}m"
end
def self.color_index(color)
@color_index_cache ||= {}
@color_index_cache[color] ||= closest_color(*get_rgb(color))
end
def self.get_rgb(color)
color = $1 if color =~ /#([0-9a-f]+)/i
hexes = case color.size
when 3
color.chars.map { |c| "#{c}#{c}" }
when 6
color.scan(/../)
else
raise "invalid color: #{color}"
end
hexes.map { |h| h.to_i(16) }
end
def self.closest_color(r, g, b)
@@colors_cache ||= {}
key = (r << 16) + (g << 8) + b
@@colors_cache.fetch(key) do
distance = MAX_DISTANCE
match = 0
xterm_colors.each_with_index do |(cr, cg, cb), i|
d = (r - cr)**2 + (g - cg)**2 + (b - cb)**2
next if d >= distance
match = iView on GitHub (pinned to bd7dad7b09)
When it happens
Trigger: Thrown at lib/rouge/formatters/terminal256.rb:138 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of rouge-ruby/rouge@bd7dad7b09 (2026-08-23).
Data as JSON: /api/errors/e3da267d4d98ab4a.
Report an issue: GitHub.