Patchwork D10764: hg-cpython: fix new occuring TypeError

login
register
mail settings
Submitter phabricator
Date May 21, 2021, 4:21 p.m.
Message ID <differential-rev-PHID-DREV-675ijvqtu3hbjxie7fz5-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/49084/
State Superseded
Headers show

Comments

phabricator - May 21, 2021, 4:21 p.m.
Alphare created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  dd339191f2dc <https://phab.mercurial-scm.org/rHGdd339191f2dccbbc9da8774594f717b1dfe4f880> introduced a minor refactoring of error types that highlighted
  a fragile error creation mechanism that was in place in the Rust `MixedIndex`.
  
  `PyErr::from_instance` also accepts a Python class, as long as it's an
  `Exception` class. Before the aforementioned commit, we never ran into a case
  where this duck-typing mechanism failed. We rectify this behavior by doing the
  instantiation ourselves.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D10764

AFFECTED FILES
  rust/hg-cpython/src/revlog.rs

CHANGE DETAILS




To: Alphare, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/rust/hg-cpython/src/revlog.rs b/rust/hg-cpython/src/revlog.rs
--- a/rust/hg-cpython/src/revlog.rs
+++ b/rust/hg-cpython/src/revlog.rs
@@ -469,7 +469,10 @@ 
         .and_then(|m| m.get(py, "RevlogError"))
     {
         Err(e) => e,
-        Ok(cls) => PyErr::from_instance(py, cls),
+        Ok(cls) => PyErr::from_instance(
+            py,
+            cls.call(py, (py.None(),), None).ok().into_py_object(py),
+        ),
     }
 }