comparison rust/hg-cpython/src/exceptions.rs @ 42560:d26e4a434fe5

rust: run rfmt on all hg-core/hg-cpython code Differential Revision: https://phab.mercurial-scm.org/D6591
author Rapha?l Gom?s <rgomes@octobus.net>
date Mon, 01 Jul 2019 10:50:18 +0200
parents 94f3a73b6672
children 326fdce22fb2
comparison
equal deleted inserted replaced
42559:e3df1e15bee9 42560:d26e4a434fe5
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 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::exc::{ValueError, RuntimeError}; 15 use cpython::exc::{RuntimeError, ValueError};
16 use cpython::{PyErr, Python, exc}; 16 use cpython::{exc, PyErr, Python};
17 use hg; 17 use hg;
18 18
19 py_exception!(rustext, GraphError, ValueError); 19 py_exception!(rustext, GraphError, ValueError);
20 20
21 impl GraphError { 21 impl GraphError {
26 } 26 }
27 hg::GraphError::WorkingDirectoryUnsupported => { 27 hg::GraphError::WorkingDirectoryUnsupported => {
28 match py 28 match py
29 .import("mercurial.error") 29 .import("mercurial.error")
30 .and_then(|m| m.get(py, "WdirUnsupported")) 30 .and_then(|m| m.get(py, "WdirUnsupported"))
31 { 31 {
32 Err(e) => e, 32 Err(e) => e,
33 Ok(cls) => PyErr::from_instance(py, cls), 33 Ok(cls) => PyErr::from_instance(py, cls),
34 } 34 }
35 } 35 }
36 } 36 }
37 } 37 }
38 } 38 }
39 39
48 } 48 }
49 } 49 }
50 } 50 }
51 } 51 }
52 52
53
54 impl PatternFileError { 53 impl PatternFileError {
55 pub fn pynew(py: Python, inner: hg::PatternFileError) -> PyErr { 54 pub fn pynew(py: Python, inner: hg::PatternFileError) -> PyErr {
56 match inner { 55 match inner {
57 hg::PatternFileError::IO(e) => { 56 hg::PatternFileError::IO(e) => {
58 let value = ( 57 let value = (e.raw_os_error().unwrap_or(2), e.to_string());
59 e.raw_os_error().unwrap_or(2),
60 e.to_string()
61 );
62 PyErr::new::<exc::IOError, _>(py, value) 58 PyErr::new::<exc::IOError, _>(py, value)
63 } 59 }
64 hg::PatternFileError::Pattern(e, l) => { 60 hg::PatternFileError::Pattern(e, l) => match e {
65 match e { 61 hg::PatternError::UnsupportedSyntax(m) => {
66 hg::PatternError::UnsupportedSyntax(m) => 62 PatternFileError::new(py, ("PatternFileError", m, l))
67 PatternFileError::new(py, ("PatternFileError", m, l))
68 } 63 }
69 } 64 },
70 } 65 }
71 } 66 }
72 } 67 }