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    ModuleClash(Box<NameClash>),
8}
9
10impl From<Box<NameClash>> for Error {
11    fn from(clash: Box<NameClash>) -> Self {
12        Error::NameClash(clash)
13    }
14}
15
16impl std::fmt::Display for Error {
17    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
18        match self {
19            Error::UnrepresentableValue { field, description } => {
20                write!(
21                    f,
22                    "value '{description}' of field '{field}' cannot be a python enum member name"
23                )
24            }
25            Error::NameClash(clash) => write!(f, "python name {clash}"),
26            Error::ModuleClash(clash) => write!(f, "python module {clash}"),
27        }
28    }
29}
30
31impl std::error::Error for Error {}