|
1 | 1 | use std::path::Path; |
2 | 2 | use std::sync::Arc; |
3 | 3 |
|
| 4 | +use pyo3::create_exception; |
4 | 5 | use pyo3::prelude::*; |
5 | 6 | use pyo3::types::{PyDict, PyList}; |
6 | 7 |
|
7 | 8 | use crate::config::limits::{ |
8 | 9 | DEFAULT_PIPELINE_TIMEOUT_SECONDS, DEFAULT_PPR_ALPHA, DEFAULT_STOPPING_THRESHOLD, |
9 | 10 | }; |
| 11 | +use crate::git::GitError as RustGitError; |
10 | 12 | use crate::mode::ScoringMode; |
11 | 13 | use crate::pipeline; |
12 | 14 | use crate::render::{DiffContextOutput, FragmentEntry}; |
13 | 15 |
|
| 16 | +create_exception!(_diffctx, GitError, pyo3::exceptions::PyException); |
| 17 | + |
| 18 | +fn map_pipeline_err(e: anyhow::Error) -> PyErr { |
| 19 | + if let Some(git_err) = e.downcast_ref::<RustGitError>() { |
| 20 | + return GitError::new_err(git_err.to_string()); |
| 21 | + } |
| 22 | + pyo3::exceptions::PyRuntimeError::new_err(e.to_string()) |
| 23 | +} |
| 24 | + |
14 | 25 | #[pyclass] |
15 | 26 | #[derive(Clone)] |
16 | 27 | pub struct PyFragment { |
@@ -247,7 +258,7 @@ fn build_diff_context<'py>( |
247 | 258 | timeout, |
248 | 259 | ) |
249 | 260 | }) |
250 | | - .map_err(|e| pyo3::exceptions::PyRuntimeError::new_err(e.to_string()))?; |
| 261 | + .map_err(map_pipeline_err)?; |
251 | 262 | let total_ms = start.elapsed().as_secs_f64() * 1000.0; |
252 | 263 |
|
253 | 264 | let dict = PyDict::new(py); |
@@ -569,6 +580,7 @@ pub fn _diffctx(m: &Bound<'_, PyModule>) -> PyResult<()> { |
569 | 580 | m.add_class::<PyProjectGraph>()?; |
570 | 581 | m.add_class::<PyQuotientGraph>()?; |
571 | 582 | m.add_class::<PyModuleMetrics>()?; |
| 583 | + m.add("GitError", m.py().get_type::<GitError>())?; |
572 | 584 | Ok(()) |
573 | 585 | } |
574 | 586 |
|
|
0 commit comments