Skip to content

Commit 32aa7d4

Browse files
committed
Put track_caller on unwrap_pyresult
1 parent 8a2cd1f commit 32aa7d4

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

vm/src/vm.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,8 @@ impl VirtualMachine {
804804
self.new_exception_empty(stop_iteration_type)
805805
}
806806

807-
// TODO: #[track_caller] when stabilized
807+
#[track_caller]
808+
#[cold]
808809
fn _py_panic_failed(&self, exc: PyBaseExceptionRef, msg: &str) -> ! {
809810
#[cfg(not(all(target_arch = "wasm32", not(target_os = "wasi"))))]
810811
{
@@ -831,13 +832,21 @@ impl VirtualMachine {
831832
panic!("{}; exception backtrace above", msg)
832833
}
833834
}
835+
#[track_caller]
834836
pub fn unwrap_pyresult<T>(&self, result: PyResult<T>) -> T {
835-
result.unwrap_or_else(|exc| {
836-
self._py_panic_failed(exc, "called `vm.unwrap_pyresult()` on an `Err` value")
837-
})
837+
match result {
838+
Ok(x) => x,
839+
Err(exc) => {
840+
self._py_panic_failed(exc, "called `vm.unwrap_pyresult()` on an `Err` value")
841+
}
842+
}
838843
}
844+
#[track_caller]
839845
pub fn expect_pyresult<T>(&self, result: PyResult<T>, msg: &str) -> T {
840-
result.unwrap_or_else(|exc| self._py_panic_failed(exc, msg))
846+
match result {
847+
Ok(x) => x,
848+
Err(exc) => self._py_panic_failed(exc, msg),
849+
}
841850
}
842851

843852
pub fn new_scope_with_builtins(&self) -> Scope {

0 commit comments

Comments
 (0)