feat(src/services): improve error handlingwith detailed logging
Replace silent exception swallowing with explicit logging via logger.error to aid debugging and observability
This commit is contained in:
5 files changed
+27
-25
No files matched your search
@@ -134,8 +134,8 @@ class BluetoothDevice(Service):
|
||||
|
||||
try:
|
||||
self._battery_proxy = _make_proxy(bus, object_path, BLUEZ_BATTERY_IFACE)
|
||||
except Exception:
|
||||
pass
|
||||
except Exception as e:
|
||||
logger.error(f"An error occurred: {e}")
|
||||
|
||||
self._prop_sub_id = bus.signal_subscribe(
|
||||
BLUEZ_SERVICE,
|
||||
@@ -153,8 +153,8 @@ class BluetoothDevice(Service):
|
||||
v = self._proxy.get_cached_property(name)
|
||||
if v is not None:
|
||||
return v.unpack()
|
||||
except Exception:
|
||||
pass
|
||||
except Exception as e:
|
||||
logger.error(f"An error occurred: {e}")
|
||||
return _unpack_variant(self._props.get(name))
|
||||
|
||||
def _get_battery_prop(self, name: str):
|
||||
@@ -319,8 +319,8 @@ class BluetoothAdapter(Service):
|
||||
v = self._proxy.get_cached_property(name)
|
||||
if v is not None:
|
||||
return v.unpack()
|
||||
except Exception:
|
||||
pass
|
||||
except Exception as e:
|
||||
logger.error(f"An error occurred: {e}")
|
||||
return _unpack_variant(self._props.get(name))
|
||||
|
||||
def _set_prop(self, name: str, value: GLib.Variant):
|
||||
|
||||
@@ -86,8 +86,8 @@ class ConfigService:
|
||||
for monitor in self._monitors:
|
||||
try:
|
||||
monitor.cancel()
|
||||
except Exception:
|
||||
pass
|
||||
except Exception as e:
|
||||
logger.error(f"An error occurred: {e}")
|
||||
self._monitors.clear()
|
||||
|
||||
def _load_config(self) -> None:
|
||||
|
||||
@@ -70,8 +70,8 @@ class PlayerService(Service):
|
||||
meta = self._player.props.metadata
|
||||
if meta and "mpris:artUrl" in meta.keys():
|
||||
return meta["mpris:artUrl"]
|
||||
except Exception:
|
||||
pass
|
||||
except Exception as e:
|
||||
logger.error(f"An error occurred: {e}")
|
||||
return ""
|
||||
|
||||
@Property(str, "readable", default_value="")
|
||||
@@ -87,8 +87,8 @@ class PlayerService(Service):
|
||||
meta = self._player.props.metadata
|
||||
if meta and "xesam:artist" in meta.keys():
|
||||
return list(meta["xesam:artist"]) or []
|
||||
except Exception:
|
||||
pass
|
||||
except Exception as e:
|
||||
logger.error(f"An error occurred: {e}")
|
||||
return []
|
||||
|
||||
@Property(str, "readable", default_value="")
|
||||
@@ -97,8 +97,8 @@ class PlayerService(Service):
|
||||
meta = self._player.props.metadata
|
||||
if meta and "xesam:album" in meta.keys():
|
||||
return meta["xesam:album"] or ""
|
||||
except Exception:
|
||||
pass
|
||||
except Exception as e:
|
||||
logger.error(f"An error occurred: {e}")
|
||||
return ""
|
||||
|
||||
@Property(str, "readable", default_value="Stopped")
|
||||
@@ -120,8 +120,8 @@ class PlayerService(Service):
|
||||
meta = self._player.props.metadata
|
||||
if meta and "mpris:length" in meta.keys():
|
||||
return int(meta["mpris:length"])
|
||||
except Exception:
|
||||
pass
|
||||
except Exception as e:
|
||||
logger.error(f"An error occurred: {e}")
|
||||
return 0
|
||||
|
||||
@Property(int, "read-write", default_value=0)
|
||||
|
||||
@@ -343,8 +343,8 @@ class NetworkClient(Service):
|
||||
return "wifi"
|
||||
if "ethernet" in str(conn_type):
|
||||
return "wired"
|
||||
except Exception:
|
||||
pass
|
||||
except Exception as e:
|
||||
logger.error(f"An error occurred: {e}")
|
||||
return None
|
||||
|
||||
def is_network_saved(self, ssid: str) -> bool:
|
||||
@@ -391,8 +391,8 @@ class NetworkClient(Service):
|
||||
if handler_id:
|
||||
try:
|
||||
device.disconnect_by_func(_on_state_changed)
|
||||
except Exception:
|
||||
pass
|
||||
except Exception as e:
|
||||
logger.error(f"An error occurred: {e}")
|
||||
|
||||
if callback:
|
||||
handler_id.append(device.connect("state-changed", _on_state_changed))
|
||||
@@ -430,8 +430,8 @@ class NetworkClient(Service):
|
||||
if handler_id:
|
||||
try:
|
||||
device.disconnect_by_func(_on_state_changed)
|
||||
except Exception:
|
||||
pass
|
||||
except Exception as e:
|
||||
logger.error(f"An error occurred: {e}")
|
||||
|
||||
handler_id.append(device.connect("state-changed", _on_state_changed))
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
from fabric.utils import logger
|
||||
|
||||
# Standard library imports
|
||||
import json
|
||||
import uuid
|
||||
@@ -36,7 +38,7 @@ class TodoService(Service):
|
||||
try:
|
||||
callback(event_type, data)
|
||||
except Exception as e:
|
||||
print(f"Error in todo callback: {e}")
|
||||
logger.error(f"Error in todo callback: {e}")
|
||||
|
||||
def _get_todos_file_path(self):
|
||||
"""Returns the path to the todos JSON file"""
|
||||
@@ -53,7 +55,7 @@ class TodoService(Service):
|
||||
else:
|
||||
self._todos = []
|
||||
except Exception as e:
|
||||
print(f"Error loading todos: {e}")
|
||||
logger.error(f"Error loading todos: {e}")
|
||||
self._todos = []
|
||||
|
||||
def _save_todos(self):
|
||||
@@ -62,7 +64,7 @@ class TodoService(Service):
|
||||
with open(self._file_path, "w", encoding="utf-8") as f:
|
||||
json.dump(self._todos, f, indent=2, ensure_ascii=False)
|
||||
except Exception as e:
|
||||
print(f"Error saving todos: {e}")
|
||||
logger.error(f"Error saving todos: {e}")
|
||||
|
||||
@Property(list, "readable")
|
||||
def todos(self):
|
||||
|
||||
Reference in new issue
Block a user