diff rust/hg-cpython/src/utils.rs @ 52074:de317a87ea6a

rust-pathauditor: match more of Python's behavior and display messages We will make use of the path auditor when running our update fast-path, and we want to output of it to be close enough.
author Rapha?l Gom?s <rgomes@octobus.net>
date Wed, 02 Oct 2024 20:29:48 +0200
parents 28a0eb21ff04
children e698e3e75420
line wrap: on
line diff
--- 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()),
     })
 }