rust/hg-cpython/src/exceptions.rs
changeset 42609 326fdce22fb2
parent 42557 d26e4a434fe5
child 42752 30320c7bf79f
equal deleted inserted replaced
42608:717686c5e461 42609:326fdce22fb2
    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::{RuntimeError, ValueError};
    15 use cpython::{
    16 use cpython::{exc, PyErr, Python};
    16     exc::{IOError, RuntimeError, ValueError},
       
    17     py_exception, PyErr, Python,
       
    18 };
    17 use hg;
    19 use hg;
    18 
    20 
    19 py_exception!(rustext, GraphError, ValueError);
    21 py_exception!(rustext, GraphError, ValueError);
    20 
    22 
    21 impl GraphError {
    23 impl GraphError {
    53 impl PatternFileError {
    55 impl PatternFileError {
    54     pub fn pynew(py: Python, inner: hg::PatternFileError) -> PyErr {
    56     pub fn pynew(py: Python, inner: hg::PatternFileError) -> PyErr {
    55         match inner {
    57         match inner {
    56             hg::PatternFileError::IO(e) => {
    58             hg::PatternFileError::IO(e) => {
    57                 let value = (e.raw_os_error().unwrap_or(2), e.to_string());
    59                 let value = (e.raw_os_error().unwrap_or(2), e.to_string());
    58                 PyErr::new::<exc::IOError, _>(py, value)
    60                 PyErr::new::<IOError, _>(py, value)
    59             }
    61             }
    60             hg::PatternFileError::Pattern(e, l) => match e {
    62             hg::PatternFileError::Pattern(e, l) => match e {
    61                 hg::PatternError::UnsupportedSyntax(m) => {
    63                 hg::PatternError::UnsupportedSyntax(m) => {
    62                     PatternFileError::new(py, ("PatternFileError", m, l))
    64                     PatternFileError::new(py, ("PatternFileError", m, l))
    63                 }
    65                 }