Fix exception handling in ui.py

- Replace 6 bare except: with except curses.error:
- Remove inline import logging, use module-level logger
- Improves safety by not catching KeyboardInterrupt/SystemExit
This commit is contained in:
pfl
2026-01-09 13:56:14 +01:00
parent f75adac97a
commit 16b5209338

15
ui.py
View File

@ -105,7 +105,7 @@ def update_autocomplete_display(window, current_input, first_word, words, ends_w
else: else:
window.addstr(1, x_pos, arg_text, curses.A_DIM) window.addstr(1, x_pos, arg_text, curses.A_DIM)
x_pos += len(arg_text) + 1 x_pos += len(arg_text) + 1
except: except curses.error:
pass pass
else: else:
# User is typing arguments # User is typing arguments
@ -134,7 +134,7 @@ def update_autocomplete_display(window, current_input, first_word, words, ends_w
match_line = f'<{arg_type}>: {" ".join(display_suggestions)}{more_indicator}' match_line = f'<{arg_type}>: {" ".join(display_suggestions)}{more_indicator}'
try: try:
window.addstr(1, 0, match_line, curses.A_DIM) window.addstr(1, 0, match_line, curses.A_DIM)
except: except curses.error:
pass pass
suggestions = arg_suggestions # Store for Tab cycling suggestions = arg_suggestions # Store for Tab cycling
suggestion_index = -1 suggestion_index = -1
@ -151,7 +151,7 @@ def update_autocomplete_display(window, current_input, first_word, words, ends_w
else: else:
window.addstr(1, x_pos, arg_text, curses.A_DIM) window.addstr(1, x_pos, arg_text, curses.A_DIM)
x_pos += len(arg_text) + 1 x_pos += len(arg_text) + 1
except: except curses.error:
pass pass
elif first_word in COMMAND_SIGNATURES and COMMAND_SIGNATURES[first_word]: elif first_word in COMMAND_SIGNATURES and COMMAND_SIGNATURES[first_word]:
@ -166,7 +166,7 @@ def update_autocomplete_display(window, current_input, first_word, words, ends_w
else: else:
window.addstr(1, x_pos, arg_text, curses.A_DIM) window.addstr(1, x_pos, arg_text, curses.A_DIM)
x_pos += len(arg_text) + 1 x_pos += len(arg_text) + 1
except: except curses.error:
pass pass
else: else:
@ -180,7 +180,7 @@ def update_autocomplete_display(window, current_input, first_word, words, ends_w
match_line = ' '.join(suggestions) match_line = ' '.join(suggestions)
try: try:
window.addstr(1, 0, match_line, curses.A_DIM) window.addstr(1, 0, match_line, curses.A_DIM)
except: except curses.error:
pass pass
return suggestions, suggestion_index, original_word return suggestions, suggestion_index, original_word
@ -367,7 +367,7 @@ class UIManager:
try: try:
window.addstr(1, 0, display_line, curses.A_DIM) window.addstr(1, 0, display_line, curses.A_DIM)
except: except curses.error:
pass pass
window.move(0, cursor_pos) window.move(0, cursor_pos)
@ -496,8 +496,7 @@ class UIManager:
curses.doupdate() # Immediate screen update curses.doupdate() # Immediate screen update
except Exception as e: except Exception as e:
import logging logger.error(f'Input error: {e}')
logging.getLogger('ui').error(f'Input error: {e}')
# Log but continue - input thread should stay alive # Log but continue - input thread should stay alive
window.move(0, cursor_pos) window.move(0, cursor_pos)