From b561fd24b51977111b7feabdf841b70d87411552 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Thu, 16 Sep 2021 21:17:36 -0700 Subject: [PATCH] Reduce indentation by returning early. --- voussoirkit/operatornotify.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/voussoirkit/operatornotify.py b/voussoirkit/operatornotify.py index 2db32b4..8117c38 100644 --- a/voussoirkit/operatornotify.py +++ b/voussoirkit/operatornotify.py @@ -120,13 +120,19 @@ class LogHandler(vlogging.StreamHandler): ''' Send all of the logged contents to notify, then reset the buffer. ''' - if self.log_buffer.getvalue(): - try: - notify(subject=self.subject, body=self.log_buffer.getvalue()) - except Exception as exc: - traceback.print_exc() - else: - self.reset_buffer() + text = self.log_buffer.getvalue() + + if not text: + return + + try: + notify(subject=self.subject, body=text) + except Exception as exc: + # Normally I'd put this into log.warning or log.error, but then we + # might get stuck in an infinite loop! Not sure what's best. + traceback.print_exc() + else: + self.reset_buffer() def reset_buffer(self): self.log_buffer = io.StringIO()