From 55deca1ec8048e0eb5095a301c98401f066a2cbb Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Thu, 2 Nov 2023 16:34:04 +0100 Subject: [PATCH] Catch additional errors on logfile Fix error on exception in session management --- cps/logger.py | 4 ++-- cps/ub.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cps/logger.py b/cps/logger.py index 13535efb..74f7fb39 100644 --- a/cps/logger.py +++ b/cps/logger.py @@ -150,7 +150,7 @@ def setup(log_file, log_level=None): else: try: file_handler = RotatingFileHandler(log_file, maxBytes=100000, backupCount=2, encoding='utf-8') - except IOError: + except (IOError, PermissionError): if log_file == DEFAULT_LOG_FILE: raise file_handler = RotatingFileHandler(DEFAULT_LOG_FILE, maxBytes=100000, backupCount=2, encoding='utf-8') @@ -177,7 +177,7 @@ def create_access_log(log_file, log_name, formatter): access_log.setLevel(logging.INFO) try: file_handler = RotatingFileHandler(log_file, maxBytes=50000, backupCount=2, encoding='utf-8') - except IOError: + except (IOError, PermissionError): if log_file == DEFAULT_ACCESS_LOG: raise file_handler = RotatingFileHandler(DEFAULT_ACCESS_LOG, maxBytes=50000, backupCount=2, encoding='utf-8') diff --git a/cps/ub.py b/cps/ub.py index db8dba03..3e478f99 100644 --- a/cps/ub.py +++ b/cps/ub.py @@ -104,7 +104,7 @@ def check_user_session(user_id, session_key): try: return bool(session.query(User_Sessions).filter(User_Sessions.user_id==user_id, User_Sessions.session_key==session_key).one_or_none()) - except (exc.OperationalError, exc.InvalidRequestError): + except (exc.OperationalError, exc.InvalidRequestError) as e: session.rollback() log.exception(e)