rust/hg-cpython/src/utils.rs
changeset 52050 de317a87ea6a
parent 52046 28a0eb21ff04
--- a/rust/hg-cpython/src/utils.rs	Wed Oct 02 18:31:32 2024 +0200
+++ b/rust/hg-cpython/src/utils.rs	Wed Oct 02 20:29:48 2024 +0200
@@ -1,5 +1,8 @@
 use cpython::exc::ValueError;
-use cpython::{PyBytes, PyDict, PyErr, PyObject, PyResult, PyTuple, Python};
+use cpython::{
+    ObjectProtocol, PyBytes, PyDict, PyErr, PyObject, PyResult, PyTuple,
+    Python, ToPyObject,
+};
 use hg::config::Config;
 use hg::errors::HgError;
 use hg::repo::{Repo, RepoError};
@@ -36,6 +39,17 @@
         HgError::RaceDetected(_) => {
             unreachable!("must not surface to the user")
         }
+        HgError::Path(path_error) => {
+            let msg = PyBytes::new(py, path_error.to_string().as_bytes());
+            let cls = py
+                .import("mercurial.error")
+                .and_then(|m| m.get(py, "InputError"))
+                .unwrap();
+            PyErr::from_instance(
+                py,
+                cls.call(py, (msg,), None).ok().into_py_object(py),
+            )
+        }
         e => PyErr::new::<cpython::exc::RuntimeError, _>(py, e.to_string()),
     })
 }