11 //! but some variants of `hg::GraphError` can be converted directly to other |
11 //! but some variants of `hg::GraphError` can be converted directly to other |
12 //! existing Python exceptions if appropriate. |
12 //! existing Python exceptions if appropriate. |
13 //! |
13 //! |
14 //! [`GraphError`]: struct.GraphError.html |
14 //! [`GraphError`]: struct.GraphError.html |
15 use cpython::{ |
15 use cpython::{ |
16 exc::{IOError, RuntimeError, ValueError}, |
16 exc::{RuntimeError, ValueError}, |
17 py_exception, PyErr, Python, |
17 py_exception, PyErr, Python, |
18 }; |
18 }; |
19 use hg; |
19 use hg; |
20 |
20 |
21 py_exception!(rustext, GraphError, ValueError); |
21 py_exception!(rustext, GraphError, ValueError); |
37 } |
37 } |
38 } |
38 } |
39 } |
39 } |
40 } |
40 } |
41 |
41 |
42 py_exception!(rustext, PatternError, RuntimeError); |
|
43 py_exception!(rustext, PatternFileError, RuntimeError); |
|
44 py_exception!(rustext, HgPathPyError, RuntimeError); |
42 py_exception!(rustext, HgPathPyError, RuntimeError); |
45 |
43 |
46 impl PatternError { |
|
47 pub fn pynew(py: Python, inner: hg::PatternError) -> PyErr { |
|
48 match inner { |
|
49 hg::PatternError::UnsupportedSyntax(m) => { |
|
50 PatternError::new(py, ("PatternError", m)) |
|
51 } |
|
52 } |
|
53 } |
|
54 } |
|
55 |
|
56 impl PatternFileError { |
|
57 pub fn pynew(py: Python, inner: hg::PatternFileError) -> PyErr { |
|
58 match inner { |
|
59 hg::PatternFileError::IO(e) => { |
|
60 let value = (e.raw_os_error().unwrap_or(2), e.to_string()); |
|
61 PyErr::new::<IOError, _>(py, value) |
|
62 } |
|
63 hg::PatternFileError::Pattern(e, l) => match e { |
|
64 hg::PatternError::UnsupportedSyntax(m) => { |
|
65 PatternFileError::new(py, ("PatternFileError", m, l)) |
|
66 } |
|
67 }, |
|
68 } |
|
69 } |
|
70 } |
|
71 |
|
72 py_exception!(shared_ref, AlreadyBorrowed, RuntimeError); |
44 py_exception!(shared_ref, AlreadyBorrowed, RuntimeError); |