equal
deleted
inserted
replaced
6 // GNU General Public License version 2 or any later version. |
6 // GNU General Public License version 2 or any later version. |
7 |
7 |
8 //! Bindings for Rust errors |
8 //! Bindings for Rust errors |
9 //! |
9 //! |
10 //! [`GraphError`] exposes `hg::GraphError` as a subclass of `ValueError` |
10 //! [`GraphError`] exposes `hg::GraphError` as a subclass of `ValueError` |
|
11 //! but some variants of `hg::GraphError` can be converted directly to other |
|
12 //! existing Python exceptions if appropriate. |
11 //! |
13 //! |
12 //! [`GraphError`]: struct.GraphError.html |
14 //! [`GraphError`]: struct.GraphError.html |
13 use cpython::exc::ValueError; |
15 use cpython::exc::ValueError; |
14 use cpython::{PyErr, Python}; |
16 use cpython::{PyErr, Python}; |
15 use hg; |
17 use hg; |
20 pub fn pynew(py: Python, inner: hg::GraphError) -> PyErr { |
22 pub fn pynew(py: Python, inner: hg::GraphError) -> PyErr { |
21 match inner { |
23 match inner { |
22 hg::GraphError::ParentOutOfRange(r) => { |
24 hg::GraphError::ParentOutOfRange(r) => { |
23 GraphError::new(py, ("ParentOutOfRange", r)) |
25 GraphError::new(py, ("ParentOutOfRange", r)) |
24 } |
26 } |
|
27 hg::GraphError::WorkingDirectoryUnsupported => { |
|
28 match py |
|
29 .import("mercurial.error") |
|
30 .and_then(|m| m.get(py, "WdirUnsupported")) |
|
31 { |
|
32 Err(e) => e, |
|
33 Ok(cls) => PyErr::from_instance(py, cls), |
|
34 } |
|
35 } |
25 } |
36 } |
26 } |
37 } |
27 } |
38 } |