refactor(src/window):improve error handling with logging

This commit is contained in:
sankalp committed 2026-06-17 05:21:36 +05:45
1 parent 420688e9a7
commit 9cbde2c58f
26 files changed
+239 -211

No files matched your search

+14 -14
View File
@@ -124,8 +124,8 @@ class BluetoothDeviceSlot(CenterBox):
for sig_id in self._signal_ids:
try:
self.device.disconnect(sig_id)
except Exception:
pass
except Exception as e:
logger.error(f"An error occurred: {e}")
self._signal_ids.clear()
self.device = None
super().destroy()
@@ -386,8 +386,8 @@ class BluetoothConnections(Box):
self.parent.hide_controlcenter()
except FileNotFoundError:
pass
except Exception:
pass
except Exception as e:
logger.error(f"An error occurred: {e}")
def update_scan_label(self):
"""Update scanning state appearance"""
@@ -485,8 +485,8 @@ class BluetoothConnections(Box):
# Always show the other devices button, regardless of available devices
self.other_devices_button.set_visible(True) # Always visible
except Exception:
pass
except Exception as e:
logger.error(f"An error occurred: {e}")
finally:
self._update_in_progress = False
@@ -515,8 +515,8 @@ class BluetoothConnections(Box):
try:
self.update_devices()
except Exception:
pass
except Exception as e:
logger.error(f"An error occurred: {e}")
return True # Continue monitoring
@@ -529,8 +529,8 @@ class BluetoothConnections(Box):
# Simply trigger update_devices which has its own safety checks
# Avoid forcing signal emissions to prevent race conditions
self.update_devices()
except Exception:
pass
except Exception as e:
logger.error(f"An error occurred: {e}")
def on_client_changed(self, *_):
"""Handle when the bluetooth client state changes"""
@@ -547,14 +547,14 @@ class BluetoothConnections(Box):
for sig_id in self._client_signal_ids:
try:
self.client.disconnect(sig_id)
except Exception:
pass
except Exception as e:
logger.error(f"An error occurred: {e}")
self._client_signal_ids.clear()
# Collapse other devices revealer
try:
self.other_devices_revealer.child_revealed = False
except Exception:
pass
except Exception as e:
logger.error(f"An error occurred: {e}")
def close_bluetooth(self):
"""Called when Bluetooth panel is being closed"""
+24 -17
View File
@@ -159,8 +159,8 @@ class BluetoothDeviceSlot(CenterBox):
for sig_id in self._signal_ids:
try:
self.device.disconnect(sig_id)
except Exception:
pass
except Exception as e:
logger.error(f"[Bluetooth] Failed to disconnect signal {sig_id}: {e}")
self._signal_ids.clear()
self.device = None
super().destroy()
@@ -200,8 +200,10 @@ class BluetoothDeviceSlot(CenterBox):
]
self.styles = new_styles
self.dimage.set_property("style-classes", " ".join(self.styles))
except Exception:
pass
except Exception as e:
logger.error(
f"[Bluetooth] Failed to update styles for {self.device.name}: {e}"
)
if (
hasattr(self.device, "battery_percentage")
@@ -482,8 +484,8 @@ class BluetoothConnections(Box):
self.parent.hide_controlcenter()
except FileNotFoundError:
pass
except Exception:
pass
except Exception as e:
logger.error(f"[Bluetooth] Failed to open bluetooth settings: {e}")
def update_scan_label(self):
"""Update scanning state appearance"""
@@ -529,7 +531,10 @@ class BluetoothConnections(Box):
else:
other_devices.append(device)
new_other_addresses.add(device.address)
except Exception:
except Exception as e:
logger.warning(
f"[Bluetooth] Failed to process device {device}: {e}"
)
continue
paired_changed = current_paired_addresses != new_paired_addresses
@@ -591,8 +596,8 @@ class BluetoothConnections(Box):
self.no_devices_label.set_visible(not has_any_devices)
self.other_devices_button.set_visible(True) # Always visible
except Exception:
pass
except Exception as e:
logger.error(f"[Bluetooth] Error during update_devices: {e}")
finally:
self._update_in_progress = False
@@ -618,8 +623,8 @@ class BluetoothConnections(Box):
try:
self.update_devices()
except Exception:
pass
except Exception as e:
logger.error(f"[Bluetooth] Error during periodic refresh: {e}")
return True
@@ -630,8 +635,8 @@ class BluetoothConnections(Box):
try:
self.update_devices()
except Exception:
pass
except Exception as e:
logger.error(f"[Bluetooth] Error during forced device refresh: {e}")
def on_client_changed(self, *_):
"""Handle when the bluetooth client state changes"""
@@ -648,13 +653,15 @@ class BluetoothConnections(Box):
for sig_id in self._client_signal_ids:
try:
self.client.disconnect(sig_id)
except Exception:
pass
except Exception as e:
logger.error(
f"[Bluetooth] Failed to disconnect client signal {sig_id}: {e}"
)
self._client_signal_ids.clear()
try:
self.other_devices_revealer.child_revealed = False
except Exception:
pass
except Exception as e:
logger.error(f"[Bluetooth] Failed to hide other devices revealer: {e}")
def close_bluetooth(self):
"""Called when Bluetooth panel is being closed"""
+12 -14
View File
@@ -1,8 +1,6 @@
import weakref
from fabric.utils import (
bulk_connect,
)
from fabric.utils import bulk_connect, logger
from fabric.widgets.box import Box
from fabric.widgets.button import Button
from fabric.widgets.image import Image
@@ -81,8 +79,8 @@ class PlayerBoxStack(Box):
for obj, handler_id in self._signal_connections:
try:
obj.disconnect(handler_id)
except Exception:
pass
except Exception as e:
logger.error(f"An error occurred: {e}")
self._signal_connections.clear()
super().destroy()
@@ -565,8 +563,8 @@ class PlayerBox(Box):
for obj, handler_id in self._signal_connections:
try:
obj.disconnect(handler_id)
except Exception:
pass
except Exception as e:
logger.error(f"An error occurred: {e}")
super().destroy()
def _on_player_next(self, *_):
@@ -586,8 +584,8 @@ class PlayerBox(Box):
self.play_pause_icon.dynamic_file(
"player/play.svg" if status == "paused" else "player/Pause.svg"
)
except Exception:
pass
except Exception as e:
logger.error(f"An error occurred: {e}")
def _on_playback_change(self, *_):
if self.exit or self.player is None:
@@ -634,7 +632,7 @@ class PlayerBox(Box):
if self.seek_bar.get_adjustment().get_upper() > 0:
self.seek_bar.set_value(min(2147483647, position_micros))
except Exception as e:
print(f"[_on_track_position] Error: {e}")
logger.error(f"[_on_track_position] Error: {e}")
def _on_seek_start(self, widget, event):
self._user_seeking = True
@@ -651,8 +649,8 @@ class PlayerBox(Box):
self.seek_bar.set_range(
0, min(2147483647, duration) if duration > 0 else 100
)
except Exception:
pass
except Exception as e:
logger.error(f"An error occurred: {e}")
def _on_scale_value_changed(self, scale: Scale):
if self.player and not self.exit and self._user_seeking:
@@ -660,8 +658,8 @@ class PlayerBox(Box):
new_position = max(-2147483648, min(2147483647, int(scale.get_value())))
self.player.position = new_position
self.position_label.set_label(self.length_str(new_position))
except Exception:
pass
except Exception as e:
logger.error(f"An error occurred: {e}")
class ExpandedPlayer(Window):
+22 -22
View File
@@ -599,14 +599,14 @@ class ModusControlCenter(AppletWindow):
try:
self.volume_scale.disconnect_by_func(self.set_volume)
self.volume_scale.disconnect_by_func(self.on_volume_scroll)
except Exception:
pass
except Exception as e:
logger.error(f"An error occurred: {e}")
if hasattr(self, "brightness_scale"):
try:
self.brightness_scale.disconnect_by_func(self.set_brightness)
self.brightness_scale.disconnect_by_func(self.on_brightness_scroll)
except Exception:
pass
except Exception as e:
logger.error(f"An error occurred: {e}")
self._signals_connected = False
self._resources_initialized = False
@@ -765,8 +765,8 @@ class ModusControlCenter(AppletWindow):
if self._caffeine_process:
try:
self._caffeine_process.terminate()
except Exception:
pass
except Exception as e:
logger.error(f"An error occurred: {e}")
self._caffeine_process = None
else:
inhibit_script = get_relative_path("../../utils/inhibit.py")
@@ -904,8 +904,8 @@ class ModusControlCenter(AppletWindow):
def close_bluetooth(self, *_):
try:
self.bluetooth_man.close_bluetooth()
except Exception:
pass
except Exception as e:
logger.error(f"An error occurred: {e}")
if self.current_view == "expanded_player":
self._crossfade_to_view("main")
else:
@@ -915,8 +915,8 @@ class ModusControlCenter(AppletWindow):
def close_wifi(self, *_):
try:
self.wifi_man.close_wifi()
except Exception:
pass
except Exception as e:
logger.error(f"An error occurred: {e}")
if self.current_view == "expanded_player":
self._crossfade_to_view("main")
else:
@@ -1072,28 +1072,28 @@ class ModusControlCenter(AppletWindow):
if hasattr(self, "volume_scale") and self.volume_scale:
try:
self.volume_scale.disconnect_by_func(self.set_volume)
except Exception:
pass
except Exception as e:
logger.error(f"An error occurred: {e}")
try:
self.volume_scale.disconnect_by_func(self.on_volume_scroll)
except Exception:
pass
except Exception as e:
logger.error(f"An error occurred: {e}")
if hasattr(self, "brightness_scale") and self.brightness_scale:
try:
self.brightness_scale.disconnect_by_func(self.set_brightness)
except Exception:
pass
except Exception as e:
logger.error(f"An error occurred: {e}")
try:
self.brightness_scale.disconnect_by_func(self.on_brightness_scroll)
except Exception:
pass
except Exception as e:
logger.error(f"An error occurred: {e}")
# Disconnect the visibility change signal on self
try:
self.disconnect_by_func(self._on_visibility_changed)
except Exception:
pass
except Exception as e:
logger.error(f"An error occurred: {e}")
self._signals_connected = False
logger.debug("All signals disconnected successfully")
@@ -1254,5 +1254,5 @@ class ModusControlCenter(AppletWindow):
logger.error(f"Failed to destroy control center: {e}")
try:
super().destroy()
except Exception:
pass
except Exception as e:
logger.error(f"An error occurred: {e}")
+10 -10
View File
@@ -1,4 +1,4 @@
from fabric.utils import GLib
from fabric.utils import GLib, logger
from fabric.widgets.box import Box
from fabric.widgets.button import Button
from fabric.widgets.image import Image
@@ -60,8 +60,8 @@ class PerAppVolumeControl(Box):
try:
if hasattr(self.control_center, "add_keybinding"):
self.control_center.add_keybinding("Escape", self._go_back)
except Exception:
pass # Ignore if keybinding fails
except Exception as e:
logger.error(f"An error occurred: {e}") # Ignore if keybinding fails
self.children = [self.header, self.scrolled_window]
@@ -174,8 +174,8 @@ class PerAppVolumeControl(Box):
for child in list(self.apps_container.get_children()):
try:
child.destroy()
except Exception:
pass
except Exception as e:
logger.error(f"An error occurred: {e}")
self.apps_container.children = []
self._app_widgets.clear()
@@ -310,7 +310,7 @@ class PerAppVolumeControl(Box):
app.volume = volume_value
except Exception as e:
print(f"Error setting volume for {app.name}: {e}")
logger.error(f"Error setting volume for {app.name}: {e}")
finally:
GLib.timeout_add(100, lambda: self._updating_volumes.discard(app.name))
@@ -331,8 +331,8 @@ class PerAppVolumeControl(Box):
if self._refresh_timer is not None:
try:
GLib.source_remove(self._refresh_timer)
except Exception:
pass
except Exception as e:
logger.error(f"An error occurred: {e}")
self._refresh_timer = None
# Disconnect audio service signals
@@ -340,8 +340,8 @@ class PerAppVolumeControl(Box):
for connection in self._signal_connections:
try:
audio_service.disconnect(connection)
except Exception:
pass
except Exception as e:
logger.error(f"An error occurred: {e}")
self._signal_connections.clear()
self._app_widgets.clear()
+6 -6
View File
@@ -101,8 +101,8 @@ class PlayerBoxStack(Box):
for obj, handler_id in self._signal_connections:
try:
obj.disconnect(handler_id)
except Exception:
pass
except Exception as e:
logger.error(f"An error occurred: {e}")
self._signal_connections.clear()
super().destroy()
@@ -451,8 +451,8 @@ class PlayerBox(Box):
self.play_pause_icon.dynamic_file(
"player/play.svg" if status == "paused" else "player/Pause.svg"
)
except Exception:
pass
except Exception as e:
logger.error(f"An error occurred: {e}")
def _on_playback_change(self, *_):
if self.exit or self.player is None:
@@ -482,6 +482,6 @@ class PlayerBox(Box):
for obj, handler_id in self._signal_connections:
try:
obj.disconnect(handler_id)
except Exception:
pass
except Exception as e:
logger.error(f"An error occurred: {e}")
super().destroy()
+25 -16
View File
@@ -1,6 +1,6 @@
import subprocess
from fabric.utils import Gdk, GLib
from fabric.utils import Gdk, GLib, logger
from fabric.widgets.box import Box
from fabric.widgets.button import Button
from fabric.widgets.centerbox import CenterBox
@@ -151,7 +151,10 @@ class WifiNetworkSlot(Box):
self.network_service.connect_wifi_bssid(
self.access_point.bssid, callback=on_open_connection_result
)
except Exception:
except Exception as e:
logger.error(
f"[WiFi] Failed to connect to {self.access_point.ssid}: {e}"
)
self._reset_connect_state()
self.on_changed()
@@ -234,7 +237,10 @@ class WifiNetworkSlot(Box):
self.network_service.connect_wifi_with_password(
self.access_point.bssid, password, callback=on_connection_result
)
except Exception:
except Exception as e:
logger.error(
f"[WiFi] Failed to initiate connection to {self.access_point.ssid}: {e}"
)
self._reset_connect_state()
if self.password_dialog:
self._show_connection_error("Connection failed. Please try again.")
@@ -447,8 +453,8 @@ class WifiConnections(Box):
self.parent.hide_controlcenter()
except FileNotFoundError:
pass
except Exception:
pass
except Exception as e:
logger.error(f"[WiFi] Failed to open network settings: {e}")
def update_networks(self, *_):
"""Update the list of available networks"""
@@ -487,7 +493,10 @@ class WifiConnections(Box):
else:
other_networks.append(access_point)
new_other_ssids.add(access_point.ssid)
except Exception:
except Exception as e:
logger.warning(
f"[WiFi] Failed to process access point {access_point}: {e}"
)
continue
known_changed = current_known_ssids != new_known_ssids
@@ -570,8 +579,8 @@ class WifiConnections(Box):
self.other_networks_button.set_visible(True) # Always visible
self.refresh_network_states()
except Exception:
pass
except Exception as e:
logger.error(f"[WiFi] Error during update_networks: {e}")
finally:
self._update_in_progress = False
@@ -619,8 +628,8 @@ class WifiConnections(Box):
try:
self.update_networks()
except Exception:
pass
except Exception as e:
logger.error(f"[WiFi] Error during periodic network refresh: {e}")
return True # Continue monitoring
@@ -631,8 +640,8 @@ class WifiConnections(Box):
try:
self.update_networks()
except Exception:
pass
except Exception as e:
logger.error(f"[WiFi] Error during forced network refresh: {e}")
def setup_pull_to_refresh(self):
"""Setup pull-to-refresh gesture for the scrolled window"""
@@ -714,15 +723,15 @@ class WifiConnections(Box):
for obj, sig_id in self._signal_ids:
try:
obj.disconnect(sig_id)
except Exception:
pass
except Exception as e:
logger.error(f"[WiFi] Failed to disconnect signal {sig_id}: {e}")
self._signal_ids.clear()
self.wifi_service = None
self.network_service = None
try:
self.other_networks_revealer.child_revealed = False
except Exception:
pass
except Exception as e:
logger.error(f"[WiFi] Failed to hide other networks revealer: {e}")
def close_wifi(self):
"""Called when WiFi panel is being closed"""