Skip to content

Commit aa183ef

Browse files
committed
Derive thiserror::Error for HexColorError (again) (#4847)
This was first done in 7b4e3a5, but was then reverted when the new renderer for 0.6 was merged (ffecb05). I'm assuming it was simply a mistake when merging. # Objective - Same as #2740, I think it was reverted by mistake when merging. > # Objective > > - Make it easy to use HexColorError with `thiserror`, i.e. converting it into other error types. > > Makes this possible: > > ```rust > #[derive(Debug, thiserror::Error)] > pub enum LdtkError { > #[error("An error occured while deserializing")] > Json(#[from] serde_json::Error), > #[error("An error occured while parsing a color")] > HexColor(#[from] bevy::render::color::HexColorError), > } > ``` > > ## Solution > > - Derive thiserror::Error the same way we do elsewhere (see query.rs for instance)
1 parent 80b08ea commit aa183ef

File tree

1 file changed

+5
-2
lines changed
  • crates/bevy_render/src/color

1 file changed

+5
-2
lines changed

crates/bevy_render/src/color/mod.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use bevy_math::{Vec3, Vec4};
77
use bevy_reflect::{FromReflect, Reflect, ReflectDeserialize};
88
use serde::{Deserialize, Serialize};
99
use std::ops::{Add, AddAssign, Mul, MulAssign};
10+
use thiserror::Error;
1011

1112
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, Reflect, FromReflect)]
1213
#[reflect(PartialEq, Serialize, Deserialize)]
@@ -1170,10 +1171,12 @@ impl MulAssign<[f32; 3]> for Color {
11701171
}
11711172
}
11721173

1173-
#[derive(Debug)]
1174+
#[derive(Debug, Error)]
11741175
pub enum HexColorError {
1176+
#[error("Unexpected length of hex string")]
11751177
Length,
1176-
Hex(hex::FromHexError),
1178+
#[error("Error parsing hex value")]
1179+
Hex(#[from] hex::FromHexError),
11771180
}
11781181

11791182
fn decode_rgb(data: &[u8]) -> Result<Color, HexColorError> {

0 commit comments

Comments
 (0)