rust/hg-cpython/src/utils.rs
changeset 52046 de317a87ea6a
parent 52042 28a0eb21ff04
child 52185 e698e3e75420
equal deleted inserted replaced
52045:a8cf6a852f11 52046:de317a87ea6a
     1 use cpython::exc::ValueError;
     1 use cpython::exc::ValueError;
     2 use cpython::{PyBytes, PyDict, PyErr, PyObject, PyResult, PyTuple, Python};
     2 use cpython::{
       
     3     ObjectProtocol, PyBytes, PyDict, PyErr, PyObject, PyResult, PyTuple,
       
     4     Python, ToPyObject,
       
     5 };
     3 use hg::config::Config;
     6 use hg::config::Config;
     4 use hg::errors::HgError;
     7 use hg::errors::HgError;
     5 use hg::repo::{Repo, RepoError};
     8 use hg::repo::{Repo, RepoError};
     6 use hg::revlog::Node;
     9 use hg::revlog::Node;
     7 use hg::utils::files::get_path_from_bytes;
    10 use hg::utils::files::get_path_from_bytes;
    33             log::trace!("Update from null fallback: {}", as_string);
    36             log::trace!("Update from null fallback: {}", as_string);
    34             PyErr::new::<FallbackError, _>(py, &as_string)
    37             PyErr::new::<FallbackError, _>(py, &as_string)
    35         }
    38         }
    36         HgError::RaceDetected(_) => {
    39         HgError::RaceDetected(_) => {
    37             unreachable!("must not surface to the user")
    40             unreachable!("must not surface to the user")
       
    41         }
       
    42         HgError::Path(path_error) => {
       
    43             let msg = PyBytes::new(py, path_error.to_string().as_bytes());
       
    44             let cls = py
       
    45                 .import("mercurial.error")
       
    46                 .and_then(|m| m.get(py, "InputError"))
       
    47                 .unwrap();
       
    48             PyErr::from_instance(
       
    49                 py,
       
    50                 cls.call(py, (msg,), None).ok().into_py_object(py),
       
    51             )
    38         }
    52         }
    39         e => PyErr::new::<cpython::exc::RuntimeError, _>(py, e.to_string()),
    53         e => PyErr::new::<cpython::exc::RuntimeError, _>(py, e.to_string()),
    40     })
    54     })
    41 }
    55 }
    42 
    56