bevyengine/bevy · error · HexColorError
Unexpected length of hex string
Error message
Unexpected length of hex string
What it means
HexColorError::Length: the hex color string's length does not match any supported format. Bevy accepts 6-digit RGB and 8-digit RGBA (with optional leading '#'); any other length (e.g. 3, 4, or 7 after '#' handling) yields this error.
Source
Thrown at crates/bevy_color/src/srgba.rs:439
impl From<Srgba> for wgpu_types::Color {
fn from(color: Srgba) -> Self {
wgpu_types::Color {
r: color.red as f64,
g: color.green as f64,
b: color.blue as f64,
a: color.alpha as f64,
}
}
}
/// Error returned if a hex string could not be parsed as a color.
#[derive(Debug, Error, PartialEq, Eq)]
pub enum HexColorError {
/// Parsing error.
#[error("Invalid hex string")]
Parse(#[from] core::num::ParseIntError),
/// Invalid length.
#[error("Unexpected length of hex string")]
Length,
/// Invalid character.
#[error("Invalid hex char")]
Char(char),
}
#[cfg(test)]
mod tests {
use crate::testing::assert_approx_eq;
use super::*;
#[test]
fn test_to_from_linear() {
let srgba = Srgba::new(0.0, 0.5, 1.0, 1.0);
let linear_rgba: LinearRgba = srgba.into();
assert_eq!(linear_rgba.red, 0.0);
assert_approx_eq!(linear_rgba.green, 0.2140, 0.0001);View on GitHub (pinned to 396ca72708)
Solutions
- Use '#RRGGBB' or '#RRGGBBAA' format
- Expand shorthand forms like '#ABC' to '#AABBCC' before parsing
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/bevy_color/src/srgba.rs:439 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of bevyengine/bevy@396ca72708 (2026-08-20).
Data as JSON: /api/errors/fee34b9901b73eee.
Report an issue: GitHub.