|
1 | | -use crate::exceptions::{ |
2 | | - CorruptCache, InvalidModuleExpression, ModuleNotPresent, NoSuchContainer, ParseError, |
3 | | -}; |
| 1 | +use crate::exceptions; |
4 | 2 | use pyo3::PyErr; |
5 | 3 | use pyo3::exceptions::PyValueError; |
6 | 4 | use ruff_python_parser::ParseError as RuffParseError; |
7 | 5 | use thiserror::Error; |
8 | 6 |
|
9 | 7 | #[derive(Debug, Error)] |
10 | | -pub enum GrimpError { |
11 | | - #[error("Module {0} is not present in the graph.")] |
12 | | - ModuleNotPresent(String), |
| 8 | +#[error("Module {0} is not present in the graph.")] |
| 9 | +pub struct ModuleNotPresent(pub String); |
| 10 | + |
| 11 | +impl From<ModuleNotPresent> for PyErr { |
| 12 | + fn from(value: ModuleNotPresent) -> Self { |
| 13 | + exceptions::ModuleNotPresent::new_err(value.to_string()) |
| 14 | + } |
| 15 | +} |
13 | 16 |
|
| 17 | +#[derive(Debug, Error)] |
| 18 | +pub enum GrimpError { |
14 | 19 | #[error("Container {0} does not exist.")] |
15 | 20 | NoSuchContainer(String), |
16 | 21 |
|
@@ -39,16 +44,17 @@ impl From<GrimpError> for PyErr { |
39 | 44 | fn from(value: GrimpError) -> Self { |
40 | 45 | // A default mapping from `GrimpError`s to python exceptions. |
41 | 46 | match value { |
42 | | - GrimpError::ModuleNotPresent(_) => ModuleNotPresent::new_err(value.to_string()), |
43 | | - GrimpError::NoSuchContainer(_) => NoSuchContainer::new_err(value.to_string()), |
| 47 | + GrimpError::NoSuchContainer(_) => { |
| 48 | + exceptions::NoSuchContainer::new_err(value.to_string()) |
| 49 | + } |
44 | 50 | GrimpError::SharedDescendants => PyValueError::new_err(value.to_string()), |
45 | 51 | GrimpError::InvalidModuleExpression(_) => { |
46 | | - InvalidModuleExpression::new_err(value.to_string()) |
| 52 | + exceptions::InvalidModuleExpression::new_err(value.to_string()) |
47 | 53 | } |
48 | 54 | GrimpError::ParseError { |
49 | 55 | line_number, text, .. |
50 | | - } => PyErr::new::<ParseError, _>((line_number, text)), |
51 | | - GrimpError::CorruptCache(_) => CorruptCache::new_err(value.to_string()), |
| 56 | + } => PyErr::new::<exceptions::ParseError, _>((line_number, text)), |
| 57 | + GrimpError::CorruptCache(_) => exceptions::CorruptCache::new_err(value.to_string()), |
52 | 58 | } |
53 | 59 | } |
54 | 60 | } |
0 commit comments