Fix logger.exception messages in example code.
authorScott Gasch <[email protected]>
Sun, 26 Feb 2023 17:34:12 +0000 (09:34 -0800)
committerScott Gasch <[email protected]>
Sun, 26 Feb 2023 17:34:12 +0000 (09:34 -0800)
examples/cron/cron.py
examples/reminder/reminder.py

index 6e0667deac9da60ef61c96b217e04f5fb327a1e6..db91af1c0c0e9f47ce0cfc6de2b0ee3c21c6b5b8 100755 (executable)
@@ -94,10 +94,10 @@ def run_command(timeout: Optional[int], timestamp_file: Optional[str]) -> int:
             logger.debug("Touching %s", timestamp_file)
             file_utils.touch_file(timestamp_file)
         return ret
-    except Exception as e:
-        logger.exception(e)
+    except Exception:
+        msg = "Cron subprocess failed; giving up."
+        logger.exception(msg)
         print("Cron subprocess failed, giving up.", file=sys.stderr)
-        logger.warning("Cron subprocess failed, giving up")
         return -1000
 
 
@@ -170,10 +170,9 @@ def main() -> int:
                             file=wf,
                         )
                 return retval
-        except lockfile.LockFileException as e:
-            logger.exception(e)
+        except lockfile.LockFileException:
             msg = f"Failed to acquire {lockfile_path}, giving up."
-            logger.error(msg)
+            logger.exception(msg)
             print(msg, file=sys.stderr)
             return 1000
     else:
index a7ed8e775c607b583354e711631b6d6adadd84e0..5fbd47639281ec97d087fd1cac1fdee298fadb13 100755 (executable)
@@ -172,10 +172,9 @@ class Reminder(object):
                     else:
                         self.handle_event_with_fixed_year(orig_date, label)
 
-            except Exception as e:
+            except Exception:
+                logger.exception("Skipping malformed line: %s", line)
                 print(f"Skipping unparsable line: {line}", file=sys.stderr)
-                logger.error("Skipping malformed line: %s", line)
-                logger.exception(e)
 
     def remind(
         self, count: Optional[int], days_ahead: Optional[int], say_date: bool