From 469f8d6d7e97b823c2c8dd6faf8f9b63977fa5b9 Mon Sep 17 00:00:00 2001 From: Jon Nelson Date: Tue, 24 Feb 2026 18:20:15 -0600 Subject: [PATCH] Check errno values in exceptions against errno. Don't hard-code errno values, instead refer to the symbols in the errno module. Also, prefer to use the `.errno` exception instance data member instead of `.args[0]`; the former is more idiomatic. --- adafruit_logging.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/adafruit_logging.py b/adafruit_logging.py index 301dabc..29ff855 100644 --- a/adafruit_logging.py +++ b/adafruit_logging.py @@ -55,6 +55,7 @@ """ +import errno import os import sys import time @@ -387,7 +388,7 @@ def doRollover(self) -> None: # Rename the current file to the next number in the sequence. os.rename(CurrentFileName, CurrentFileNamePlus) except OSError as e: - if e.args[0] == 2: + if e.errno == errno.ENOENT: # File does not exsist. This is okay. pass else: @@ -405,7 +406,7 @@ def GetLogSize(self) -> int | None: self.stream.flush() # We need to call this or the file size is always zero. LogFileSize = os.stat(self._LogFileName)[6] except OSError as e: - if e.args[0] == 2: + if e.errno == errno.ENOENT: # Log file does not exsist. This is okay. LogFileSize = None else: