Skip to content

Commit aec7f84

Browse files
committed
Print exception context
1 parent 1887589 commit aec7f84

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

vm/src/exceptions.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,22 @@ fn exception_init(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
2020

2121
// print excption chain
2222
pub fn print_exception(vm: &VirtualMachine, exc: &PyObjectRef) {
23+
let mut had_casue = false;
2324
if let Ok(cause) = vm.get_attribute(exc.clone(), "__cause__") {
2425
if !vm.get_none().is(&cause) {
26+
had_casue = true;
2527
print_exception(vm, &cause);
2628
println!("\nThe above exception was the direct cause of the following exception:\n");
2729
}
2830
}
31+
if !had_casue {
32+
if let Ok(context) = vm.get_attribute(exc.clone(), "__context__") {
33+
if !vm.get_none().is(&context) {
34+
print_exception(vm, &context);
35+
println!("\nDuring handling of the above exception, another exception occurred:\n");
36+
}
37+
}
38+
}
2939
print_exception_inner(vm, exc)
3040
}
3141

0 commit comments

Comments
 (0)