server: improve add_warning method
Add an exc_info parameter that optionally takes an exception that is passed to the logging function. This will log the traceback without an additional logging call. Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
11d15f96d1
commit
0ff1d79b5b
|
@ -318,10 +318,9 @@ class MoonrakerApp:
|
||||||
svr.listen(port, address)
|
svr.listen(port, address)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
svr_type = "HTTPS" if "ssl_options" in args else "HTTP"
|
svr_type = "HTTPS" if "ssl_options" in args else "HTTP"
|
||||||
logging.exception(f"{svr_type} Server Start Failed")
|
|
||||||
self.server.add_warning(
|
self.server.add_warning(
|
||||||
f"Failed to start {svr_type} server: {e}. See moonraker.log "
|
f"Failed to start {svr_type} server: {e}. See moonraker.log "
|
||||||
"for more details."
|
"for more details.", exc_info=e
|
||||||
)
|
)
|
||||||
return None
|
return None
|
||||||
return svr
|
return svr
|
||||||
|
|
|
@ -31,7 +31,7 @@ class ButtonManager:
|
||||||
btn = GpioButton(cfg)
|
btn = GpioButton(cfg)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
msg = f"Failed to load button [{cfg.get_name()}]\n{e}"
|
msg = f"Failed to load button [{cfg.get_name()}]\n{e}"
|
||||||
self.server.add_warning(msg)
|
self.server.add_warning(msg, exc_info=e)
|
||||||
continue
|
continue
|
||||||
self.buttons[btn.name] = btn
|
self.buttons[btn.name] = btn
|
||||||
self.server.register_notification("button:button_event")
|
self.server.register_notification("button:button_event")
|
||||||
|
|
|
@ -1849,12 +1849,11 @@ class InotifyObserver(BaseFileSystemObserver):
|
||||||
old_root.clear_events()
|
old_root.clear_events()
|
||||||
try:
|
try:
|
||||||
root_node = InotifyRootNode(self, root, root_path)
|
root_node = InotifyRootNode(self, root, root_path)
|
||||||
except Exception:
|
except Exception as e:
|
||||||
logging.exception(f"Inotify: failed to create root node '{root}'")
|
|
||||||
self.server.add_warning(
|
self.server.add_warning(
|
||||||
f"file_manager: Failed to create inotify root node {root}. "
|
f"file_manager: Failed to create inotify root node {root}. "
|
||||||
"See moonraker.log for details.",
|
"See moonraker.log for details.",
|
||||||
log=False
|
exc_info=e
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
self.watched_roots[root] = root_node
|
self.watched_roots[root] = root_node
|
||||||
|
@ -1877,12 +1876,11 @@ class InotifyObserver(BaseFileSystemObserver):
|
||||||
for root, node in self.watched_roots.items():
|
for root, node in self.watched_roots.items():
|
||||||
try:
|
try:
|
||||||
evts = node.scan_node()
|
evts = node.scan_node()
|
||||||
except Exception:
|
except Exception as e:
|
||||||
logging.exception(f"Inotify: failed to scan root '{root}'")
|
|
||||||
self.server.add_warning(
|
self.server.add_warning(
|
||||||
f"file_manager: Failed to scan inotify root node '{root}'. "
|
f"file_manager: Failed to scan inotify root node '{root}'. "
|
||||||
"See moonraker.log for details.",
|
"See moonraker.log for details.",
|
||||||
log=False
|
exc_info=e
|
||||||
)
|
)
|
||||||
continue
|
continue
|
||||||
if not evts:
|
if not evts:
|
||||||
|
|
|
@ -1712,8 +1712,7 @@ class InstallValidator:
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
has_error = True
|
has_error = True
|
||||||
msg = f"Failed to validate {name}: {e}"
|
msg = f"Failed to validate {name}: {e}"
|
||||||
logging.exception(msg)
|
self.server.add_warning(msg, exc_info=e)
|
||||||
self.server.add_warning(msg, log=False)
|
|
||||||
fm.disable_write_access()
|
fm.disable_write_access()
|
||||||
else:
|
else:
|
||||||
self.validation_enabled = False
|
self.validation_enabled = False
|
||||||
|
|
|
@ -46,7 +46,7 @@ class Notifier:
|
||||||
logging.info(f"Registered notifier: '{notifier.get_name()}'")
|
logging.info(f"Registered notifier: '{notifier.get_name()}'")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
msg = f"Failed to load notifier[{cfg.get_name()}]\n{e}"
|
msg = f"Failed to load notifier[{cfg.get_name()}]\n{e}"
|
||||||
self.server.add_warning(msg)
|
self.server.add_warning(msg, exc_info=e)
|
||||||
continue
|
continue
|
||||||
self.notifiers[notifier.get_name()] = notifier
|
self.notifiers[notifier.get_name()] = notifier
|
||||||
|
|
||||||
|
@ -170,12 +170,12 @@ class NotifierInstance:
|
||||||
fm: FileManager = self.server.lookup_component("file_manager")
|
fm: FileManager = self.server.lookup_component("file_manager")
|
||||||
try:
|
try:
|
||||||
rendered = self.attach.render(context)
|
rendered = self.attach.render(context)
|
||||||
except self.server.error:
|
except self.server.error as e:
|
||||||
logging.exception(f"notifier {self.name}: Failed to render attachment")
|
|
||||||
self.server.add_warning(
|
self.server.add_warning(
|
||||||
f"[notifier {self.name}]: The attachment is not valid. The "
|
f"[notifier {self.name}]: The attachment is not valid. The "
|
||||||
"template failed to render.",
|
"template failed to render.",
|
||||||
f"notifier {self.name}"
|
f"notifier {self.name}",
|
||||||
|
exc_info=e
|
||||||
)
|
)
|
||||||
self.attach = None
|
self.attach = None
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -74,7 +74,7 @@ class PrinterPower:
|
||||||
dev = dev_class(cfg)
|
dev = dev_class(cfg)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
msg = f"Failed to load power device [{cfg.get_name()}]\n{e}"
|
msg = f"Failed to load power device [{cfg.get_name()}]\n{e}"
|
||||||
self.server.add_warning(msg)
|
self.server.add_warning(msg, exc_info=e)
|
||||||
continue
|
continue
|
||||||
self.devices[dev.get_name()] = dev
|
self.devices[dev.get_name()] = dev
|
||||||
|
|
||||||
|
|
|
@ -267,7 +267,7 @@ class Sensors:
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# Ensures that configuration errors are shown to the user
|
# Ensures that configuration errors are shown to the user
|
||||||
self.server.add_warning(
|
self.server.add_warning(
|
||||||
f"Failed to configure sensor [{cfg.get_name()}]\n{e}"
|
f"Failed to configure sensor [{cfg.get_name()}]\n{e}", exc_info=e
|
||||||
)
|
)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
|
@ -130,7 +130,8 @@ class UpdateManager:
|
||||||
self.updaters[name] = deployer(cfg, self.cmd_helper)
|
self.updaters[name] = deployer(cfg, self.cmd_helper)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.server.add_warning(
|
self.server.add_warning(
|
||||||
f"[update_manager]: Failed to load extension {name}: {e}"
|
f"[update_manager]: Failed to load extension {name}: {e}",
|
||||||
|
exc_info=e
|
||||||
)
|
)
|
||||||
|
|
||||||
self.cmd_request_lock = asyncio.Lock()
|
self.cmd_request_lock = asyncio.Lock()
|
||||||
|
|
|
@ -377,7 +377,7 @@ class WLED:
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# Ensures errors such as "Color not supported" are visible
|
# Ensures errors such as "Color not supported" are visible
|
||||||
msg = f"Failed to initialise strip [{cfg.get_name()}]\n{e}"
|
msg = f"Failed to initialise strip [{cfg.get_name()}]\n{e}"
|
||||||
self.server.add_warning(msg)
|
self.server.add_warning(msg, exc_info=e)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Register two remote methods for GCODE
|
# Register two remote methods for GCODE
|
||||||
|
|
|
@ -226,13 +226,17 @@ class Server:
|
||||||
logging.info(item)
|
logging.info(item)
|
||||||
|
|
||||||
def add_warning(
|
def add_warning(
|
||||||
self, warning: str, warn_id: Optional[str] = None, log: bool = True
|
self,
|
||||||
|
warning: str,
|
||||||
|
warn_id: Optional[str] = None,
|
||||||
|
log: bool = True,
|
||||||
|
exc_info: Optional[BaseException] = None
|
||||||
) -> str:
|
) -> str:
|
||||||
if warn_id is None:
|
if warn_id is None:
|
||||||
warn_id = str(id(warning))
|
warn_id = str(id(warning))
|
||||||
self.warnings[warn_id] = warning
|
self.warnings[warn_id] = warning
|
||||||
if log:
|
if log:
|
||||||
logging.warning(warning)
|
logging.warning(warning, exc_info=exc_info)
|
||||||
return warn_id
|
return warn_id
|
||||||
|
|
||||||
def remove_warning(self, warn_id: str) -> None:
|
def remove_warning(self, warn_id: str) -> None:
|
||||||
|
@ -246,9 +250,9 @@ class Server:
|
||||||
if ret is not None:
|
if ret is not None:
|
||||||
await ret
|
await ret
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.exception(f"Component [{name}] failed post init")
|
self.add_warning(
|
||||||
self.add_warning(f"Component '{name}' failed to load with "
|
f"Component '{name}' failed to load with error: {e}", exc_info=e
|
||||||
f"error: {e}")
|
)
|
||||||
self.set_failed_component(name)
|
self.set_failed_component(name)
|
||||||
|
|
||||||
def load_components(self) -> None:
|
def load_components(self) -> None:
|
||||||
|
|
Loading…
Reference in New Issue