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

View File

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

View File

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

View File

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

View File

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