##// END OF EJS Templates
rust-nodemap: add utils for propagating errors...
Georges Racinet -
r44993:26dd35ac default
parent child Browse files
Show More
@@ -1,16 +1,16 b''
1 // revlog.rs
1 // revlog.rs
2 //
2 //
3 // Copyright 2019 Georges Racinet <georges.racinet@octobus.net>
3 // Copyright 2019-2020 Georges Racinet <georges.racinet@octobus.net>
4 //
4 //
5 // This software may be used and distributed according to the terms of the
5 // This software may be used and distributed according to the terms of the
6 // GNU General Public License version 2 or any later version.
6 // GNU General Public License version 2 or any later version.
7
7
8 use crate::cindex;
8 use crate::cindex;
9 use cpython::{
9 use cpython::{
10 ObjectProtocol, PyClone, PyDict, PyModule, PyObject, PyResult, PyTuple,
10 exc::ValueError, ObjectProtocol, PyClone, PyDict, PyErr, PyModule,
11 Python, PythonObject, ToPyObject,
11 PyObject, PyResult, PyTuple, Python, PythonObject, ToPyObject,
12 };
12 };
13 use hg::Revision;
13 use hg::{nodemap::NodeMapError, NodeError, Revision};
14 use std::cell::RefCell;
14 use std::cell::RefCell;
15
15
16 /// Return a Struct implementing the Graph trait
16 /// Return a Struct implementing the Graph trait
@@ -224,6 +224,43 b' impl MixedIndex {'
224 }
224 }
225 }
225 }
226
226
227 fn revlog_error(py: Python) -> PyErr {
228 match py
229 .import("mercurial.error")
230 .and_then(|m| m.get(py, "RevlogError"))
231 {
232 Err(e) => e,
233 Ok(cls) => PyErr::from_instance(py, cls),
234 }
235 }
236
237 fn rev_not_in_index(py: Python, rev: Revision) -> PyErr {
238 PyErr::new::<ValueError, _>(
239 py,
240 format!(
241 "Inconsistency: Revision {} found in nodemap \
242 is not in revlog index",
243 rev
244 ),
245 )
246 }
247
248 /// Standard treatment of NodeMapError
249 fn nodemap_error(py: Python, err: NodeMapError) -> PyErr {
250 match err {
251 NodeMapError::MultipleResults => revlog_error(py),
252 NodeMapError::RevisionNotInIndex(r) => rev_not_in_index(py, r),
253 NodeMapError::InvalidNodePrefix(s) => invalid_node_prefix(py, &s),
254 }
255 }
256
257 fn invalid_node_prefix(py: Python, ne: &NodeError) -> PyErr {
258 PyErr::new::<ValueError, _>(
259 py,
260 format!("Invalid node or prefix: {:?}", ne),
261 )
262 }
263
227 /// Create the module, with __package__ given from parent
264 /// Create the module, with __package__ given from parent
228 pub fn init_module(py: Python, package: &str) -> PyResult<PyModule> {
265 pub fn init_module(py: Python, package: &str) -> PyResult<PyModule> {
229 let dotted_name = &format!("{}.revlog", package);
266 let dotted_name = &format!("{}.revlog", package);
General Comments 0
You need to be logged in to leave comments. Login now