This repository was archived by the owner on Jun 22, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +36
-6
lines changed
Expand file tree Collapse file tree 4 files changed +36
-6
lines changed Original file line number Diff line number Diff line change @@ -273,10 +273,14 @@ def _process_message(message, ws):
273273 elif 'return' in message :
274274 call_id = message ['return' ]
275275 if call_id in _call_return_callbacks :
276- callback = _call_return_callbacks .pop (call_id )
277- callback (message ['value' ])
276+ callback , error_callback = _call_return_callbacks .pop (call_id )
277+ if message ['status' ] == 'ok' :
278+ callback (message ['value' ])
279+ elif message ['status' ] == 'error' and error_callback is not None :
280+ error_callback (message ['error' ], message ['stack' ])
278281 else :
279282 _call_return_values [call_id ] = message ['value' ]
283+
280284 else :
281285 print ('Invalid message received: ' , message )
282286
@@ -321,9 +325,9 @@ def _call_return(call):
321325 global _js_result_timeout
322326 call_id = call ['call' ]
323327
324- def return_func (callback = None ):
328+ def return_func (callback = None , error_callback = None ):
325329 if callback is not None :
326- _call_return_callbacks [call_id ] = callback
330+ _call_return_callbacks [call_id ] = ( callback , error_callback )
327331 else :
328332 for w in range (_js_result_timeout ):
329333 if call_id in _call_return_values :
Original file line number Diff line number Diff line change @@ -131,8 +131,17 @@ eel = {
131131 if ( message . hasOwnProperty ( 'call' ) ) {
132132 // Python making a function call into us
133133 if ( message . name in eel . _exposed_functions ) {
134- let return_val = eel . _exposed_functions [ message . name ] ( ...message . args ) ;
135- eel . _websocket . send ( eel . _toJSON ( { 'return' : message . call , 'value' : return_val } ) ) ;
134+ try {
135+ let return_val = eel . _exposed_functions [ message . name ] ( ...message . args ) ;
136+ eel . _websocket . send ( eel . _toJSON ( { 'return' : message . call , 'status' :'ok' , 'value' : return_val } ) ) ;
137+ } catch ( err ) {
138+ debugger
139+ eel . _websocket . send ( eel . _toJSON (
140+ { 'return' : message . call ,
141+ 'status' :'error' ,
142+ 'error' : err . message ,
143+ 'stack' : err . stack } ) ) ;
144+ }
136145 }
137146 } else if ( message . hasOwnProperty ( 'return' ) ) {
138147 // Python returning a value to us
Original file line number Diff line number Diff line change @@ -18,10 +18,21 @@ def py_exception(error):
1818def print_num (n ):
1919 print ('Got this from Javascript:' , n )
2020
21+
22+ def print_num_failed (error , stack ):
23+ print ("This is an example of what javascript errors would look like:" )
24+ print ("\t Error: " , error )
25+ print ("\t Stack: " , stack )
26+
2127# Call Javascript function, and pass explicit callback function
2228eel .js_random ()(print_num )
2329
2430# Do the same with an inline callback
2531eel .js_random ()(lambda n : print ('Got this from Javascript:' , n ))
2632
33+ # Show error handling
34+ eel .js_with_error ()(print_num , print_num_failed )
35+
36+
2737eel .start ('callbacks.html' , size = (400 , 300 ))
38+
Original file line number Diff line number Diff line change 1010 function js_random ( ) {
1111 return Math . random ( ) ;
1212 }
13+
14+ eel . expose ( js_with_error ) ;
15+ function js_with_error ( ) {
16+ var test = 0 ;
17+ test . something ( "does not exist" ) ;
18+ }
1319
1420 function print_num ( n ) {
1521 console . log ( 'Got this from Python: ' + n ) ;
You can’t perform that action at this time.
0 commit comments