dump more info during exceptions

This commit is contained in:
alfrix
2022-08-09 18:59:35 -03:00
parent 6863d1c32e
commit 200dca9dd3
5 changed files with 25 additions and 27 deletions

View File

@@ -60,10 +60,10 @@ class KlipperScreenConfig:
logging.info(f"====== Saved Def ======\n{saved_def}\n=======================") logging.info(f"====== Saved Def ======\n{saved_def}\n=======================")
# This is the final config # This is the final config
# self.log_config(self.config) # self.log_config(self.config)
except KeyError as e: except KeyError as Kerror:
raise ConfigError(f"Error reading config: {self.config_path}") from e raise ConfigError(f"Error reading config: {self.config_path}\n{Kerror}") from Kerror
except Exception: except Exception as e:
logging.exception("Unknown error with config") logging.exception(f"Unknown error with config:\n{e}")
printers = sorted([i for i in self.config.sections() if i.startswith("printer ")]) printers = sorted([i for i in self.config.sections() if i.startswith("printer ")])
self.printers = [ self.printers = [
@@ -317,7 +317,6 @@ class KlipperScreenConfig:
cfg = self.config[name] cfg = self.config[name]
return {opt: cfg.get("gcode", None) if opt == "gcode" else cfg.getint(opt, None) for opt in cfg} return {opt: cfg.get("gcode", None) if opt == "gcode" else cfg.getint(opt, None) for opt in cfg}
def get_printer_config(self, name): def get_printer_config(self, name):
if not name.startswith("printer "): if not name.startswith("printer "):
name = f"printer {name}" name = f"printer {name}"
@@ -385,8 +384,8 @@ class KlipperScreenConfig:
try: try:
with open(filepath, 'w') as file: with open(filepath, 'w') as file:
file.write(contents) file.write(contents)
except Exception: except Exception as e:
logging.error(f"Error writing configuration file in {filepath}") logging.error(f"Error writing configuration file in {filepath}:\n{e}")
def set(self, section, name, value): def set(self, section, name, value):
self.config.set(section, name, value) self.config.set(section, name, value)
@@ -426,8 +425,8 @@ class KlipperScreenConfig:
try: try:
item["params"] = json.loads(cfg.get("params", "{}")) item["params"] = json.loads(cfg.get("params", "{}"))
except Exception: except Exception as e:
logging.debug(f"Unable to parse parameters for [{name}]") logging.exception(f"Unable to parse parameters for [{name}]:\n{e}")
item["params"] = {} item["params"] = {}
return {name[(len(menu) + 6):]: item} return {name[(len(menu) + 6):]: item}

View File

@@ -112,8 +112,8 @@ class KlippyFiles:
def add_file_callback(self, callback): def add_file_callback(self, callback):
try: try:
self.callbacks.append(callback) self.callbacks.append(callback)
except Exception: except Exception as e:
logging.debug(f"Callback not found: {callback}") logging.debug(f"Callback not found: {callback}:\n{e}")
def process_update(self, data): def process_update(self, data):
if 'item' in data and data['item']['root'] != 'gcodes': if 'item' in data and data['item']['root'] != 'gcodes':

View File

@@ -293,8 +293,8 @@ class BasePanel(ScreenPanel):
env.install_gettext_translations(self.lang) env.install_gettext_translations(self.lang)
j2_temp = env.from_string(title) j2_temp = env.from_string(title)
title = j2_temp.render() title = j2_temp.render()
except Exception: except Exception as e:
logging.debug(f"Error parsing jinja for title: {title}") logging.debug(f"Error parsing jinja for title: {title}\n{e}")
self.titlelbl.set_label(f"{self._screen.connecting_to_printer} | {title}") self.titlelbl.set_label(f"{self._screen.connecting_to_printer} | {title}")

View File

@@ -114,6 +114,6 @@ class MenuPanel(ScreenPanel):
if result == 'True': if result == 'True':
return True return True
return False return False
except Exception: except Exception as e:
logging.debug(f"Error evaluating enable statement: {enable}") logging.debug(f"Error evaluating enable statement: {enable}\n{e}")
return False return False

View File

@@ -299,7 +299,7 @@ class KlipperScreen(Gtk.Window):
try: try:
return self.load_panel[panel](*args) return self.load_panel[panel](*args)
except Exception as e: except Exception as e:
msg = f"Unable to create panel {panel}" msg = f"Unable to create panel {panel}\n{e}"
logging.exception(msg) logging.exception(msg)
raise Exception(msg) from e raise Exception(msg) from e
@@ -316,7 +316,7 @@ class KlipperScreen(Gtk.Window):
if panel_name in self.panels: if panel_name in self.panels:
del self.panels[panel_name] del self.panels[panel_name]
logging.exception(f"Unable to load panel {panel_type}") logging.exception(f"Unable to load panel {panel_type}")
self.show_error_modal(f"Unable to load panel {panel_type}", e) self.show_error_modal(f"Unable to load panel {panel_type}", f"{e}")
return return
if hasattr(self.panels[panel_name], "process_update"): if hasattr(self.panels[panel_name], "process_update"):
@@ -344,8 +344,8 @@ class KlipperScreen(Gtk.Window):
if hasattr(self.panels[panel_name], "activate"): if hasattr(self.panels[panel_name], "activate"):
self.panels[panel_name].activate() self.panels[panel_name].activate()
self.show_all() self.show_all()
except Exception: except Exception as e:
logging.exception("Error attaching panel") logging.exception(f"Error attaching panel:\n{e}")
self._cur_panels.append(panel_name) self._cur_panels.append(panel_name)
logging.debug(f"Current panel hierarchy: {self._cur_panels}") logging.debug(f"Current panel hierarchy: {self._cur_panels}")
@@ -484,8 +484,8 @@ class KlipperScreen(Gtk.Window):
try: try:
with open(theme_style_conf) as f: with open(theme_style_conf) as f:
style_options.update(json.load(f)) style_options.update(json.load(f))
except Exception: except Exception as e:
logging.error("Unable to parse custom template conf file.") logging.error(f"Unable to parse custom template conf file:\n{e}")
self.gtk.color_list = style_options['graph_colors'] self.gtk.color_list = style_options['graph_colors']
@@ -769,7 +769,7 @@ class KlipperScreen(Gtk.Window):
for panel in list(self.panels): for panel in list(self.panels):
if panel not in ["printer_select", "splash_screen"]: if panel not in ["printer_select", "splash_screen"]:
del self.panels[panel] del self.panels[panel]
if dialog in self.dialogs: for dialog in self.dialogs:
dialog.destroy() dialog.destroy()
def state_paused(self, prev_state): def state_paused(self, prev_state):
@@ -891,8 +891,8 @@ class KlipperScreen(Gtk.Window):
env.install_gettext_translations(self.lang) env.install_gettext_translations(self.lang)
j2_temp = env.from_string(text) j2_temp = env.from_string(text)
text = j2_temp.render() text = j2_temp.render()
except Exception: except Exception as e:
logging.debug("Error parsing jinja for confirm_send_action") logging.debug(f"Error parsing jinja for confirm_send_action\n{e}")
label = Gtk.Label() label = Gtk.Label()
label.set_markup(text) label.set_markup(text)
@@ -907,7 +907,6 @@ class KlipperScreen(Gtk.Window):
self.confirm.destroy() self.confirm.destroy()
self.confirm = self.gtk.Dialog(self, buttons, label, self._confirm_send_action_response, method, params) self.confirm = self.gtk.Dialog(self, buttons, label, self._confirm_send_action_response, method, params)
def _confirm_send_action_response(self, widget, response_id, method, params): def _confirm_send_action_response(self, widget, response_id, method, params):
if response_id == Gtk.ResponseType.OK: if response_id == Gtk.ResponseType.OK:
self._send_action(widget, method, params) self._send_action(widget, method, params)
@@ -1138,5 +1137,5 @@ def main():
if __name__ == "__main__": if __name__ == "__main__":
try: try:
main() main()
except Exception: except Exception as ex:
logging.exception("Fatal error in main loop") logging.exception(f"Fatal error in main loop:\n{ex}")