bevyengine/bevy · error · HexColorError
Invalid hex string
Error message
Invalid hex string
What it means
HexColorError::Parse: the integer portion of the hex color string failed to parse (e.g. non-hex digits where digits were expected). It wraps the underlying ParseIntError; commonly triggered by strings like '#GG0000' or stray characters in the hex literal.
Source
Thrown at crates/bevy_color/src/srgba.rs:436
}
#[cfg(feature = "wgpu-types")]
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);View on GitHub (pinned to 396ca72708)
Solutions
- Use only hexadecimal digits (0-9, a-f) in the color string
- Remove stray characters or whitespace before parsing
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/bevy_color/src/srgba.rs:436 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/0bf4e2f6af197840.
Report an issue: GitHub.