Mercurial > public > mercurial-scm > hg
comparison rust/hg-cpython/src/exceptions.rs @ 41349:ee943a920606 stable
rust: error for WdirUnsupported with cpython conversion as exception
This introduces WorkingDirectoryUnsupported as an enum variant
of GraphError in the core and converts it to the expected
`mercurial.error.WdirUnsupported`.
author | Georges Racinet <georges.racinet@octobus.net> |
---|---|
date | Wed, 23 Jan 2019 07:47:04 -0500 |
parents | dcf818267bc1 |
children | 94f3a73b6672 |
comparison
equal
deleted
inserted
replaced
41348:2f54f31c41aa | 41349:ee943a920606 |
---|---|
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 } |