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