Skip to main content

refix_codegen/python/
error.rs

1use crate::NameClash;
2
3#[derive(Debug, Eq, PartialEq)]
4pub enum Error {
5    UnrepresentableValue { field: String, description: String },
6    NameClash(Box<NameClash>),
7}
8
9impl From<Box<NameClash>> for Error {
10    fn from(clash: Box<NameClash>) -> Self {
11        Error::NameClash(clash)
12    }
13}
14
15impl std::fmt::Display for Error {
16    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
17        match self {
18            Error::UnrepresentableValue { field, description } => {
19                write!(
20                    f,
21                    "value '{description}' of field '{field}' cannot be a python enum member name"
22                )
23            }
24            Error::NameClash(clash) => write!(f, "python name {clash}"),
25        }
26    }
27}
28
29impl std::error::Error for Error {}