File tree Expand file tree Collapse file tree 2 files changed +27
-6
lines changed Expand file tree Collapse file tree 2 files changed +27
-6
lines changed Original file line number Diff line number Diff line change @@ -36,14 +36,18 @@ function runCodeFromTextarea() {
36
36
if ( result !== null ) {
37
37
consoleElement . value += `\n${ result } \n` ;
38
38
}
39
- } catch ( e ) {
40
- errorElement . textContent = e ;
41
- console . error ( e ) ;
39
+ } catch ( err ) {
40
+ if ( err instanceof WebAssembly . RuntimeError ) {
41
+ err = window . __RUSTPYTHON_ERROR || err ;
42
+ }
43
+ errorElement . textContent = err ;
44
+ console . error ( err ) ;
42
45
}
43
46
}
44
47
45
48
document
46
49
. getElementById ( 'run-btn' )
47
50
. addEventListener ( 'click' , runCodeFromTextarea ) ;
48
51
49
- runCodeFromTextarea ( ) ; // Run once for demo
52
+ // Run once for demo
53
+ runCodeFromTextarea ( ) ;
Original file line number Diff line number Diff line change @@ -9,17 +9,34 @@ extern crate wasm_bindgen;
9
9
extern crate web_sys;
10
10
11
11
use js_sys:: { Object , Reflect , TypeError } ;
12
+ use std:: panic;
12
13
use wasm_bindgen:: prelude:: * ;
13
14
14
15
pub use crate :: vm_class:: * ;
15
16
16
17
const PY_EVAL_VM_ID : & str = "__py_eval_vm" ;
17
18
18
- extern crate console_error_panic_hook;
19
+ fn panic_hook ( info : & panic:: PanicInfo ) {
20
+ // If something errors, just ignore it; we don't want to panic in the panic hook
21
+ use js_sys:: WebAssembly :: RuntimeError ;
22
+ let window = match web_sys:: window ( ) {
23
+ Some ( win) => win,
24
+ None => return ,
25
+ } ;
26
+ let msg = & info. to_string ( ) ;
27
+ let _ = Reflect :: set ( & window, & "__RUSTPYTHON_ERROR_MSG" . into ( ) , & msg. into ( ) ) ;
28
+ let error = RuntimeError :: new ( & msg) ;
29
+ let _ = Reflect :: set ( & window, & "__RUSTPYTHON_ERROR" . into ( ) , & error) ;
30
+ let stack = match Reflect :: get ( & error, & "stack" . into ( ) ) {
31
+ Ok ( stack) => stack,
32
+ Err ( _) => return ,
33
+ } ;
34
+ let _ = Reflect :: set ( & window, & "__RUSTPYTHON_ERROR_STACK" . into ( ) , & stack. into ( ) ) ;
35
+ }
19
36
20
37
#[ wasm_bindgen( start) ]
21
38
pub fn setup_console_error ( ) {
22
- std:: panic:: set_hook ( Box :: new ( console_error_panic_hook :: hook ) ) ;
39
+ std:: panic:: set_hook ( Box :: new ( panic_hook ) ) ;
23
40
}
24
41
25
42
// Hack to comment out wasm-bindgen's generated typescript definitons
You can’t perform that action at this time.
0 commit comments