@@ -548,14 +548,30 @@ impl VirtualMachine {
548
548
549
549
// TODO: #[track_caller] when stabilized
550
550
fn _py_panic_failed ( & self , exc : & PyBaseExceptionRef , msg : & str ) -> ! {
551
- let show_backtrace = env:: var_os ( "RUST_BACKTRACE" ) . map_or ( false , |v| & v != "0" ) ;
552
- let after = if show_backtrace {
553
- exceptions:: print_exception ( self , exc) ;
554
- "exception backtrace above"
555
- } else {
556
- "run with RUST_BACKTRACE=1 to see Python backtrace"
557
- } ;
558
- panic ! ( "{}; {}" , msg, after)
551
+ #[ cfg( not( all( target_arch = "wasm32" , not( target_os = "wasi" ) ) ) ) ]
552
+ {
553
+ let show_backtrace = env:: var_os ( "RUST_BACKTRACE" ) . map_or ( false , |v| & v != "0" ) ;
554
+ let after = if show_backtrace {
555
+ exceptions:: print_exception ( self , exc) ;
556
+ "exception backtrace above"
557
+ } else {
558
+ "run with RUST_BACKTRACE=1 to see Python backtrace"
559
+ } ;
560
+ panic ! ( "{}; {}" , msg, after)
561
+ }
562
+ #[ cfg( all( target_arch = "wasm32" , not( target_os = "wasi" ) ) ) ]
563
+ {
564
+ use wasm_bindgen:: prelude:: * ;
565
+ #[ wasm_bindgen]
566
+ extern "C" {
567
+ #[ wasm_bindgen( js_namespace = console) ]
568
+ fn error ( s : & str ) ;
569
+ }
570
+ let mut s = Vec :: < u8 > :: new ( ) ;
571
+ exceptions:: write_exception ( & mut s, self , exc) . unwrap ( ) ;
572
+ error ( std:: str:: from_utf8 ( & s) . unwrap ( ) ) ;
573
+ panic ! ( "{}; exception backtrace above" , msg)
574
+ }
559
575
}
560
576
pub fn unwrap_pyresult < T > ( & self , result : PyResult < T > ) -> T {
561
577
result. unwrap_or_else ( |exc| {
0 commit comments