annotate rust/hg-cpython/src/exceptions.rs @ 41694:0c7b353ce100

rust-cpython: binding for headrevs() This uses the core `dagops::retain_heads` to give a Rust implementation to `mercurial.dagop.headrevs`. Testing happens for now from `test-rust-ancestors.py` (for quick and minimal change), but it'd made more sense to put the binary index data elsewhere and to create a new test python module
author Georges Racinet <georges.racinet@octobus.net>
date Thu, 10 Jan 2019 18:25:18 +0100
parents ee943a920606
children 94f3a73b6672
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
41184
dcf818267bc1 rust-cpython: rustdoc improvements
Georges Racinet <georges.racinet@octobus.net>
parents: 40965
diff changeset
1 // ancestors.rs
dcf818267bc1 rust-cpython: rustdoc improvements
Georges Racinet <georges.racinet@octobus.net>
parents: 40965
diff changeset
2 //
dcf818267bc1 rust-cpython: rustdoc improvements
Georges Racinet <georges.racinet@octobus.net>
parents: 40965
diff changeset
3 // Copyright 2018 Georges Racinet <gracinet@anybox.fr>
dcf818267bc1 rust-cpython: rustdoc improvements
Georges Racinet <georges.racinet@octobus.net>
parents: 40965
diff changeset
4 //
dcf818267bc1 rust-cpython: rustdoc improvements
Georges Racinet <georges.racinet@octobus.net>
parents: 40965
diff changeset
5 // This software may be used and distributed according to the terms of the
dcf818267bc1 rust-cpython: rustdoc improvements
Georges Racinet <georges.racinet@octobus.net>
parents: 40965
diff changeset
6 // GNU General Public License version 2 or any later version.
dcf818267bc1 rust-cpython: rustdoc improvements
Georges Racinet <georges.racinet@octobus.net>
parents: 40965
diff changeset
7
dcf818267bc1 rust-cpython: rustdoc improvements
Georges Racinet <georges.racinet@octobus.net>
parents: 40965
diff changeset
8 //! Bindings for Rust errors
dcf818267bc1 rust-cpython: rustdoc improvements
Georges Racinet <georges.racinet@octobus.net>
parents: 40965
diff changeset
9 //!
dcf818267bc1 rust-cpython: rustdoc improvements
Georges Racinet <georges.racinet@octobus.net>
parents: 40965
diff changeset
10 //! [`GraphError`] exposes `hg::GraphError` as a subclass of `ValueError`
41349
ee943a920606 rust: error for WdirUnsupported with cpython conversion as exception
Georges Racinet <georges.racinet@octobus.net>
parents: 41184
diff changeset
11 //! but some variants of `hg::GraphError` can be converted directly to other
ee943a920606 rust: error for WdirUnsupported with cpython conversion as exception
Georges Racinet <georges.racinet@octobus.net>
parents: 41184
diff changeset
12 //! existing Python exceptions if appropriate.
41184
dcf818267bc1 rust-cpython: rustdoc improvements
Georges Racinet <georges.racinet@octobus.net>
parents: 40965
diff changeset
13 //!
dcf818267bc1 rust-cpython: rustdoc improvements
Georges Racinet <georges.racinet@octobus.net>
parents: 40965
diff changeset
14 //! [`GraphError`]: struct.GraphError.html
40965
5532823e8c18 rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
15 use cpython::exc::ValueError;
5532823e8c18 rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
16 use cpython::{PyErr, Python};
5532823e8c18 rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
17 use hg;
5532823e8c18 rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
18
5532823e8c18 rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
19 py_exception!(rustext, GraphError, ValueError);
5532823e8c18 rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
20
5532823e8c18 rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
21 impl GraphError {
5532823e8c18 rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
22 pub fn pynew(py: Python, inner: hg::GraphError) -> PyErr {
5532823e8c18 rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
23 match inner {
5532823e8c18 rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
24 hg::GraphError::ParentOutOfRange(r) => {
5532823e8c18 rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
25 GraphError::new(py, ("ParentOutOfRange", r))
5532823e8c18 rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
26 }
41349
ee943a920606 rust: error for WdirUnsupported with cpython conversion as exception
Georges Racinet <georges.racinet@octobus.net>
parents: 41184
diff changeset
27 hg::GraphError::WorkingDirectoryUnsupported => {
ee943a920606 rust: error for WdirUnsupported with cpython conversion as exception
Georges Racinet <georges.racinet@octobus.net>
parents: 41184
diff changeset
28 match py
ee943a920606 rust: error for WdirUnsupported with cpython conversion as exception
Georges Racinet <georges.racinet@octobus.net>
parents: 41184
diff changeset
29 .import("mercurial.error")
ee943a920606 rust: error for WdirUnsupported with cpython conversion as exception
Georges Racinet <georges.racinet@octobus.net>
parents: 41184
diff changeset
30 .and_then(|m| m.get(py, "WdirUnsupported"))
ee943a920606 rust: error for WdirUnsupported with cpython conversion as exception
Georges Racinet <georges.racinet@octobus.net>
parents: 41184
diff changeset
31 {
ee943a920606 rust: error for WdirUnsupported with cpython conversion as exception
Georges Racinet <georges.racinet@octobus.net>
parents: 41184
diff changeset
32 Err(e) => e,
ee943a920606 rust: error for WdirUnsupported with cpython conversion as exception
Georges Racinet <georges.racinet@octobus.net>
parents: 41184
diff changeset
33 Ok(cls) => PyErr::from_instance(py, cls),
ee943a920606 rust: error for WdirUnsupported with cpython conversion as exception
Georges Racinet <georges.racinet@octobus.net>
parents: 41184
diff changeset
34 }
ee943a920606 rust: error for WdirUnsupported with cpython conversion as exception
Georges Racinet <georges.racinet@octobus.net>
parents: 41184
diff changeset
35 }
40965
5532823e8c18 rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
36 }
5532823e8c18 rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
37 }
5532823e8c18 rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
38 }