-
Notifications
You must be signed in to change notification settings - Fork 280
/
Copy pathmod.rs
35 lines (32 loc) · 1.15 KB
/
mod.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use pyo3::prelude::*;
mod line_error;
mod location;
mod types;
mod validation_exception;
mod value_exception;
pub use self::line_error::{
InputValue, LineErrorCollector, ToErrorValue, ValError, ValLineError, ValResult, ValResultExt,
ValidationControlFlow,
};
pub use self::location::LocItem;
pub use self::types::{list_all_errors, ErrorType, ErrorTypeDefaults, Number};
pub use self::validation_exception::ValidationError;
pub use self::value_exception::{PydanticCustomError, PydanticKnownError, PydanticOmit, PydanticUseDefault};
pub fn py_err_string(py: Python, err: PyErr) -> String {
let value = err.value_bound(py);
match value.get_type().qualname() {
Ok(type_name) => match value.str() {
Ok(py_str) => {
let str_cow = py_str.to_string_lossy();
let str = str_cow.as_ref();
if !str.is_empty() {
format!("{type_name}: {str}")
} else {
type_name.to_string()
}
}
Err(_) => format!("{type_name}: <exception str() failed>"),
},
Err(_) => "Unknown Error".to_string(),
}
}