Mercurial > public > mercurial-scm > hg-stable
diff rust/hg-pyo3/src/exceptions.rs @ 52790:32008b1e7104
rust-pyo3-revlog: Python RevlogError with helper
This is singled out because it defines the inner submobule
for Mercurial Python exceptions
author | Georges Racinet <georges.racinet@cloudcrane.io> |
---|---|
date | Tue, 24 Dec 2024 18:14:07 +0100 |
parents | 2fb13c3f4496 |
children | 42b219a1404a |
line wrap: on
line diff
--- a/rust/hg-pyo3/src/exceptions.rs Tue Dec 24 18:16:38 2024 +0100 +++ b/rust/hg-pyo3/src/exceptions.rs Tue Dec 24 18:14:07 2024 +0100 @@ -39,3 +39,16 @@ pub fn map_lock_error<T>(e: std::sync::PoisonError<T>) -> PyErr { PyRuntimeError::new_err(format!("In Rust PyO3 bindings: {e}")) } + +/// Submodule to hold Mercurial errors defined on the Python side +/// +/// This is better for clarity, as many hg-core errors have the same names +/// as their Python world counterparts +pub mod mercurial_py_errors { + pyo3::import_exception!(mercurial.error, RevlogError); +} + +#[allow(dead_code)] +pub fn revlog_error_from_msg(e: impl ToString) -> PyErr { + mercurial_py_errors::RevlogError::new_err(e.to_string().into_bytes()) +}