bevyengine/bevy · error · HexColorError
Invalid hex char
Error message
Invalid hex char
What it means
HexColorError::Char: the string has a valid length but contains a character outside the hexadecimal alphabet at the position carried in the error, so u32::from_str_radix cannot parse the color channels.
Source
Thrown at crates/bevy_color/src/srgba.rs:442
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);
assert_approx_eq!(linear_rgba.blue, 1.0, 0.0001);
assert_eq!(linear_rgba.alpha, 1.0);
let srgba2: Srgba = linear_rgba.into();View on GitHub (pinned to 396ca72708)
Solutions
- Replace the offending character with a hex digit (0-9, a-f)
- Double-check color constants for typos like 'O' instead of '0'
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/bevy_color/src/srgba.rs:442 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/36426287ae559dfa.
Report an issue: GitHub.