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