Improved error handling

This commit is contained in:
Mark Qvist 2023-10-28 15:54:29 +02:00
parent 11439dcabd
commit 6bb38d2f51

View File

@ -276,7 +276,7 @@ class SidebandApp(MDApp):
) )
self.hw_error_dialog = MDDialog( self.hw_error_dialog = MDDialog(
title="Hardware Error", title="Hardware Error",
text="When starting a connected RNode, Reticulum reported the following error:\n\n[i]"+description+"[/i]", text="When starting a connected RNode, Reticulum reported the following error:\n\n[i]"+str(description)+"[/i]",
buttons=[ yes_button ], buttons=[ yes_button ],
# elevation=0, # elevation=0,
) )
@ -692,7 +692,7 @@ class SidebandApp(MDApp):
ok_button = MDRectangleFlatButton(text="OK",font_size=dp(18)) ok_button = MDRectangleFlatButton(text="OK",font_size=dp(18))
dialog = MDDialog( dialog = MDDialog(
title="Message Scan", title="Message Scan",
text=info_text, text=str(info_text),
buttons=[ ok_button ], buttons=[ ok_button ],
# elevation=0, # elevation=0,
) )
@ -708,7 +708,7 @@ class SidebandApp(MDApp):
ok_button = MDRectangleFlatButton(text="OK",font_size=dp(18)) ok_button = MDRectangleFlatButton(text="OK",font_size=dp(18))
dialog = MDDialog( dialog = MDDialog(
title="Error", title="Error",
text=info_text, text=str(info_text),
buttons=[ ok_button ], buttons=[ ok_button ],
# elevation=0, # elevation=0,
) )
@ -1115,9 +1115,10 @@ class SidebandApp(MDApp):
Clock.schedule_once(cb, 0.10) Clock.schedule_once(cb, 0.10)
def get_connectivity_text(self): def get_connectivity_text(self):
try:
connectivity_status = "" connectivity_status = ""
if RNS.vendor.platformutils.get_platform() == "android": if RNS.vendor.platformutils.get_platform() == "android":
connectivity_status = self.sideband.getstate("service.connectivity_status") connectivity_status = str(self.sideband.getstate("service.connectivity_status"))
else: else:
if self.sideband.reticulum.is_connected_to_shared_instance: if self.sideband.reticulum.is_connected_to_shared_instance:
@ -1126,6 +1127,9 @@ class SidebandApp(MDApp):
connectivity_status = "Sideband is currently running a standalone or master Reticulum instance on this system. Use the [b]rnstatus[/b] utility to obtain full connectivity info." connectivity_status = "Sideband is currently running a standalone or master Reticulum instance on this system. Use the [b]rnstatus[/b] utility to obtain full connectivity info."
return connectivity_status return connectivity_status
except Exception as e:
RNS.log("An error occurred while retrieving connectivity status: "+str(e), RNS.LOG_ERROR)
return "Could not retrieve connectivity status"
def connectivity_status(self, sender): def connectivity_status(self, sender):
hs = dp(22) hs = dp(22)
@ -1133,12 +1137,12 @@ class SidebandApp(MDApp):
yes_button = MDRectangleFlatButton(text="OK",font_size=dp(18)) yes_button = MDRectangleFlatButton(text="OK",font_size=dp(18))
dialog = MDDialog( dialog = MDDialog(
title="Connectivity Status", title="Connectivity Status",
text=self.get_connectivity_text(), text=str(self.get_connectivity_text()),
buttons=[ yes_button ], buttons=[ yes_button ],
# elevation=0, # elevation=0,
) )
def cs_updater(dt): def cs_updater(dt):
dialog.text = self.get_connectivity_text() dialog.text = str(self.get_connectivity_text())
def dl_yes(s): def dl_yes(s):
self.connectivity_updater.cancel() self.connectivity_updater.cancel()
dialog.dismiss() dialog.dismiss()
@ -3946,6 +3950,7 @@ Thank you very much for using Free Communications Systems.
self.root.ids.screen_manager.current = "broadcasts_screen" self.root.ids.screen_manager.current = "broadcasts_screen"
self.root.ids.nav_drawer.set_state("closed") self.root.ids.nav_drawer.set_state("closed")
self.sideband.setstate("app.displaying", self.root.ids.screen_manager.current) self.sideband.setstate("app.displaying", self.root.ids.screen_manager.current)
raise OSError("Just a test")
class CustomOneLineIconListItem(OneLineIconListItem): class CustomOneLineIconListItem(OneLineIconListItem):
icon = StringProperty() icon = StringProperty()
@ -3953,7 +3958,21 @@ class CustomOneLineIconListItem(OneLineIconListItem):
class MDMapIconButton(MDIconButton): class MDMapIconButton(MDIconButton):
pass pass
from kivy.base import ExceptionManager, ExceptionHandler
class SidebandExceptionHandler(ExceptionHandler):
def handle_exception(self, e):
etype = type(e)
if etype != SystemExit:
import traceback
exception_info = "".join(traceback.TracebackException.from_exception(e).format())
RNS.log(f"An unhandled {str(type(e))} exception occurred: {str(e)}", RNS.LOG_ERROR)
RNS.log(exception_info)
return ExceptionManager.PASS
else:
return ExceptionManager.RAISE
def run(): def run():
ExceptionManager.add_handler(SidebandExceptionHandler())
SidebandApp().run() SidebandApp().run()
if __name__ == "__main__": if __name__ == "__main__":