@@ -284,8 +284,8 @@ def get_book_move(self):
284284 self .__book_move = entry .move
285285 except IndexError :
286286 logging .warning ('No more book move.' )
287- except :
288- logging .warning ( 'Unexpected error in probing polyglot book move.' )
287+ except Exception :
288+ logging .exception ( 'Failed to get book move.' )
289289 finally :
290290 reader .close ()
291291
@@ -420,14 +420,15 @@ def configure_engine(self):
420420 self .engine .configure ({n ['name' ]: user_value })
421421 logging .info ('Set {} to {}' .format (
422422 n ['name' ], user_value ))
423- except Exception as e :
424- logging .warning ('{}' .format (e ))
423+ except Exception :
424+ logging .exception ('{Failed to configure '
425+ 'engine}' )
425426
426427 # Don't use UCI_Analyse mode
427428 try :
428429 self .engine .configure ({'UCI_AnalyseMode' : False })
429- except :
430- pass
430+ except Exception :
431+ logging . exception ( 'Failed to set UCI_AnalyseMode.' )
431432
432433 def run (self ):
433434 """
@@ -447,17 +448,17 @@ def run(self):
447448 logging .warning ('Failed to start {}.' .format (self .engine_path_and_file ))
448449 self .eng_queue .put ('bestmove {}' .format (self .bm ))
449450 return
450- except Exception as e :
451- logging .warning ('Failed to start {}.' .format (self . engine_path_and_file ))
452- logging . warning ( e )
451+ except Exception :
452+ logging .exception ('Failed to start {}.' .format (
453+ self . engine_path_and_file ) )
453454 self .eng_queue .put ('bestmove {}' .format (self .bm ))
454455 return
455456
456457 # Set engine option values
457458 try :
458459 self .configure_engine ()
459- except Exception as e :
460- logging .warning ( '{} in configuring engine.'. format ( e ) )
460+ except Exception :
461+ logging .exception ( 'Failed to configure engine.' )
461462
462463 # Set search limits
463464 if self .tc_type == 'delay' :
@@ -534,8 +535,8 @@ def run(self):
534535 and self .max_depth != MAX_DEPTH :
535536 logging .info ('Max depth limit is reached.' )
536537 break
537- except :
538- logging .info ( 'Error in parsing engine search info' )
538+ except Exception :
539+ logging .exception ( 'Failed to parse search info. ' )
539540 else :
540541 result = self .engine .play (self .board , limit ,info = chess .engine .INFO_ALL )
541542 logging .info ('result: {}' .format (result ))
@@ -589,8 +590,8 @@ def run(self):
589590 try :
590591 result = self .engine .play (self .board , limit )
591592 self .bm = result .move
592- except Exception as e :
593- logging .exception ('Error in running engine' )
593+ except Exception :
594+ logging .exception ('Failed to get engine bestmove. ' )
594595 self .eng_queue .put ('bestmove {}' .format (self .bm ))
595596 logging .info ('bestmove {}' .format (self .bm ))
596597
@@ -601,8 +602,8 @@ def quit_engine(self):
601602 self .engine .quit ()
602603 except AttributeError :
603604 logging .info ('AttributeError, self.engine is already None' )
604- except Exception as e :
605- logging .info ( 'Unexpected exception {}' . format ( e ) )
605+ except Exception :
606+ logging .exception ( 'Failed to quit engine.' )
606607
607608 def short_variation_san (self ):
608609 """ Returns variation in san but without move numbers """
@@ -848,7 +849,7 @@ def get_engine_id_name(self, path_and_file, q):
848849 creationflags = subprocess .CREATE_NO_WINDOW )
849850 id_name = engine .id ['name' ]
850851 engine .quit ()
851- except :
852+ except Exception :
852853 logging .exception ('Failed to get id name.' )
853854
854855 q .put (['Done' , id_name ])
@@ -869,8 +870,8 @@ def get_engine_hash(self, eng_id_name):
869870 logging .info ('This engine {} has no options.' .format (
870871 eng_id_name ))
871872 break
872- except Exception as err :
873- logging .info ( 'Unexpected error {}.' . format ( err ) )
873+ except Exception :
874+ logging .exception ( 'Failed to get engine hash.' )
874875
875876 return eng_hash
876877
@@ -894,8 +895,8 @@ def get_engine_threads(self, eng_id_name):
894895 logging .info ('This engine {} has no options.' .format (
895896 eng_id_name ))
896897 break
897- except Exception as err :
898- logging .info ( 'Unexpected error {}.' . format ( err ) )
898+ except Exception :
899+ logging .exception ( 'Failed to get engine threads.' )
899900
900901 return eng_threads
901902
@@ -1154,10 +1155,8 @@ def check_engine_config_file(self):
11541155 engine = chess .engine .SimpleEngine .popen_uci (
11551156 engine_path_and_file , cwd = folder ,
11561157 creationflags = subprocess .CREATE_NO_WINDOW )
1157- except Exception as e :
1158- logging .warning (
1159- 'Failed to start {}.' .format (engine_path_and_file ))
1160- logging .warning (e )
1158+ except Exception :
1159+ logging .exception ('Failed to start engine.' )
11611160 continue
11621161
11631162 engine_id_name = engine .id ['name' ]
@@ -1243,14 +1242,11 @@ def update_text_box(self, window, msg, is_hide):
12431242 window .FindElement ('search_info_all_k' ).Update (
12441243 '' if is_hide else msg_line )
12451244 else :
1246- # print(msg_str)
1247- # best_move = chess.Move.from_uci(msg.split()[1])
1248-
12491245 # Best move can be None because engine dies
12501246 try :
12511247 best_move = chess .Move .from_uci (msg .split ()[1 ])
1252- except :
1253- logging .warning ('Engine sent a {} bestmove .' .format (best_move ))
1248+ except Exception :
1249+ logging .exception ('Engine sent {} .' .format (best_move ))
12541250 sg .Popup ('Engine error, it sent a {} bestmove.\n ' .format (
12551251 best_move ) + 'Back to Neutral mode, it is better to '
12561252 'change engine {}.' .format (
@@ -1344,8 +1340,9 @@ def fen_to_psg_board(self, window):
13441340
13451341 try :
13461342 pc = board .piece_at (s ^ 56 )
1347- except :
1343+ except Exception :
13481344 pc = None
1345+ logging .exception ('Failed to get piece.' )
13491346
13501347 if pc is not None :
13511348 pt = pc .piece_type
@@ -1593,8 +1590,9 @@ def set_depth_limit(self):
15931590
15941591 try :
15951592 user_depth = int (user_depth )
1596- except :
1593+ except Exception :
15971594 user_depth = self .max_depth
1595+ logging .exception ('Failed to get user depth.' )
15981596
15991597 self .max_depth = min (MAX_DEPTH , max (MIN_DEPTH , user_depth ))
16001598
@@ -1718,8 +1716,8 @@ def play_game(self, window, engine_id_name, board):
17181716 self .get_fen ()
17191717 self .set_new_game ()
17201718 board = chess .Board (self .fen )
1721- except :
1722- logging .info ('Error in parsing FEN from clipboard.' )
1719+ except Exception :
1720+ logging .exception ('Error in parsing FEN from clipboard.' )
17231721 continue
17241722
17251723 self .fen_to_psg_board (window )
@@ -1819,7 +1817,7 @@ def play_game(self, window, engine_id_name, board):
18191817 # Reformat msg, remove the word pv at the end
18201818 msg_line = ' ' .join (msg .split ()[0 :- 1 ])
18211819 window .Element ('advise_info_k' ).Update (msg_line )
1822- except :
1820+ except Exception :
18231821 continue
18241822
18251823 if 'bestmove' in msg :
@@ -1829,8 +1827,8 @@ def play_game(self, window, engine_id_name, board):
18291827 msg_line = ' ' .join (msg_line .split ()[0 :3 ])
18301828 msg_line += ' - ' + self .adviser_id_name
18311829 window .Element ('advise_info_k' ).Update (msg_line )
1832- except Exception as e :
1833- logging .warning ('Adviser engine error as {}' . format ( e ) )
1830+ except Exception :
1831+ logging .exception ('Adviser engine error' )
18341832 sg .Popup ('Adviser engine {} error.\n ' .format (
18351833 self .adviser_id_name ) + \
18361834 'It is better to change this engine.\n ' +
@@ -1966,8 +1964,8 @@ def play_game(self, window, engine_id_name, board):
19661964 self .get_fen ()
19671965 self .set_new_game ()
19681966 board = chess .Board (self .fen )
1969- except :
1970- logging .info ('Error in parsing FEN from clipboard.' )
1967+ except Exception :
1968+ logging .exception ('Error in parsing FEN from clipboard.' )
19711969 continue
19721970
19731971 self .fen_to_psg_board (window )
@@ -2232,7 +2230,7 @@ def play_game(self, window, engine_id_name, board):
22322230 # Get the engine search info and display it in GUI text boxes
22332231 try :
22342232 msg = self .queue .get_nowait ()
2235- except :
2233+ except Exception :
22362234 continue
22372235
22382236 msg_str = str (msg )
@@ -2620,7 +2618,7 @@ def main_loop(self):
26202618 'Players are displayed. Done! in ' +
26212619 str (elapse ) + 's' )
26222620 break
2623- except :
2621+ except Exception :
26242622 continue
26252623 t .join ()
26262624 player_list = msg [0 ]
@@ -2636,6 +2634,9 @@ def main_loop(self):
26362634 'pressing the Browse button followed by Display Players.' ,
26372635 title = win_title , icon = 'Icon/pecg.ico' )
26382636 break
2637+ except Exception :
2638+ logging .exception ('Failed to get player.' )
2639+ break
26392640
26402641 t1 = time .perf_counter ()
26412642 que = queue .Queue ()
@@ -2659,7 +2660,7 @@ def main_loop(self):
26592660 else :
26602661 w .Element ('status_k' ).Update (
26612662 msg + '/' + str (sum_games ))
2662- except :
2663+ except Exception :
26632664 continue
26642665 t .join ()
26652666
@@ -2865,7 +2866,7 @@ def main_loop(self):
28652866 try :
28662867 msg = que .get_nowait ()
28672868 break
2868- except :
2869+ except Exception :
28692870 pass
28702871 t .join ()
28712872
@@ -2915,9 +2916,9 @@ def main_loop(self):
29152916 'button.' ,
29162917 title = button_title ,
29172918 icon = 'Icon/pecg.ico' )
2918- except :
2919- logging .info ('Failed to get engine file '
2920- ' and path ' )
2919+ except Exception :
2920+ logging .exception ('Failed to get engine '
2921+ 'path and file ' )
29212922
29222923 # Outside add window while loop
29232924 add_win .Close ()
@@ -2935,7 +2936,7 @@ def main_loop(self):
29352936 try :
29362937 msg = que .get_nowait ()
29372938 break
2938- except :
2939+ except Exception :
29392940 continue
29402941 t .join ()
29412942
@@ -2983,7 +2984,7 @@ def main_loop(self):
29832984
29842985 try :
29852986 engine_id_name = v ['engine_id_name_k' ][0 ]
2986- except :
2987+ except Exception :
29872988 sg .Popup ('Please select an engine to modify.' ,
29882989 title = '/Edit/Modify' ,
29892990 icon = 'Icon/pecg.ico' )
@@ -3171,7 +3172,7 @@ def main_loop(self):
31713172 if e == 'Delete' :
31723173 try :
31733174 engine_id_name = v ['engine_id_name_k' ][0 ]
3174- except :
3175+ except Exception :
31753176 sg .Popup ('Please select an engine to delete.' ,
31763177 title = button_title , icon = 'Icon/pecg.ico' )
31773178 continue
@@ -3246,8 +3247,8 @@ def main_loop(self):
32463247 except IndexError :
32473248 logging .info ('User presses OK but did not select '
32483249 'an engine.' )
3249- except Exception as err :
3250- logging .info ( 'Unexpected errror {}.' . format ( err ) )
3250+ except Exception :
3251+ logging .exception ( 'Failed to set engine.' )
32513252 finally :
32523253 if current_engine_id_name != self .opp_id_name :
32533254 logging .info ('User selected a new opponent {'
@@ -3300,8 +3301,8 @@ def main_loop(self):
33003301 adviser_eng_id_name )
33013302 except IndexError :
33023303 logging .info ('User presses OK but did not select an engine' )
3303- except Exception as err :
3304- logging .info ( 'Unexpected errror {}' . format ( err ) )
3304+ except Exception :
3305+ logging .exception ( 'Failed to set engine.' )
33053306 break
33063307
33073308 window .Enable ()
0 commit comments