diff --git a/rust/Cargo.lock b/rust/Cargo.lock --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -722,6 +722,7 @@ dependencies = [ "pyo3", "python3-sys", "stable_deref_trait", + "vcsgraph", ] [[package]] diff --git a/rust/hg-pyo3/Cargo.toml b/rust/hg-pyo3/Cargo.toml --- a/rust/hg-pyo3/Cargo.toml +++ b/rust/hg-pyo3/Cargo.toml @@ -18,4 +18,5 @@ log = "0.4.17" derive_more = "0.99.17" env_logger = "0.9.3" lazy_static = "*" +vcsgraph = "0.2.0" diff --git a/rust/hg-pyo3/src/exceptions.rs b/rust/hg-pyo3/src/exceptions.rs --- a/rust/hg-pyo3/src/exceptions.rs +++ b/rust/hg-pyo3/src/exceptions.rs @@ -1,4 +1,34 @@ -use pyo3::create_exception; use pyo3::exceptions::PyValueError; +use pyo3::import_exception; +use pyo3::{create_exception, PyErr}; + +use crate::revision::PyRevision; create_exception!(pyo3_rustext, GraphError, PyValueError); +import_exception!(mercurial.error, WdirUnsupported); + +impl GraphError { + pub fn from_hg(inner: hg::GraphError) -> PyErr { + match inner { + hg::GraphError::ParentOutOfRange(r) => { + GraphError::new_err(("ParentOutOfRange", PyRevision(r.0))) + } + } + } + pub fn from_vcsgraph(inner: vcsgraph::graph::GraphReadError) -> PyErr { + match inner { + vcsgraph::graph::GraphReadError::InconsistentGraphData => { + GraphError::new_err("InconsistentGraphData") + } + vcsgraph::graph::GraphReadError::InvalidKey => { + GraphError::new_err("ParentOutOfRange") + } + vcsgraph::graph::GraphReadError::KeyedInvalidKey(r) => { + GraphError::new_err(("ParentOutOfRange", r)) + } + vcsgraph::graph::GraphReadError::WorkingDirectoryUnsupported => { + WdirUnsupported::new_err(()) + } + } + } +}