Skip to main content

ursus_materials/
error.rs

1use crate::value::PropertyId;
2use std::fmt;
3
4#[derive(Debug)]
5pub enum MaterialError {
6    MissingProperty {
7        material: String,
8        strategy: &'static str,
9        property: PropertyId,
10    },
11    TypeMismatch {
12        material: String,
13        property: PropertyId,
14        expected: &'static str,
15        actual: &'static str,
16    },
17    UnknownStrategy(String),
18}
19
20impl fmt::Display for MaterialError {
21    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
22        match self {
23            Self::MissingProperty { material, strategy, property } => {
24                write!(f, "material '{material}' is missing required property '{property}' for strategy '{strategy}'")
25            }
26            Self::TypeMismatch { material, property, expected, actual } => write!(
27                f,
28                "material '{material}' property '{property}' has wrong type: expected {expected}, got {actual}"
29            ),
30            Self::UnknownStrategy(name) => write!(f, "no shading strategy registered under name '{name}'"),
31        }
32    }
33}
34
35impl std::error::Error for MaterialError {}