diff options
author | Frederick Muriuki Muriithi | 2025-05-12 11:14:34 -0500 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2025-05-12 11:14:34 -0500 |
commit | 06a3658b94d78296797b9f2af2d12d73f2c54932 (patch) | |
tree | 853a84c6eefd2cedbab0668bd48a7508ddb9bd22 /scripts/rqtl2/entry.py | |
parent | bb16f9e7488d7e5b9138025d08e326b5588beff4 (diff) | |
download | gn-uploader-06a3658b94d78296797b9f2af2d12d73f2c54932.tar.gz |
Handle exceptions within the `with` to prevent silent failure
One, or both of the context managers is "swallowing" exceptions,
leading to silent failures. This change manually handles the
exceptions within the context manager to avoid such silent failures.
Diffstat (limited to 'scripts/rqtl2/entry.py')
-rw-r--r-- | scripts/rqtl2/entry.py | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/scripts/rqtl2/entry.py b/scripts/rqtl2/entry.py index 327ed2c..e837aa8 100644 --- a/scripts/rqtl2/entry.py +++ b/scripts/rqtl2/entry.py @@ -24,16 +24,17 @@ def build_main( ) -> Callable[[],int]: """Build a function to be used as an entry-point for scripts.""" def main(): - try: logging.basicConfig( format=( "%(asctime)s - %(levelname)s %(name)s: " "(%(pathname)s: %(lineno)d) %(message)s"), level=args.loglevel) logger = logging.getLogger(loggername) - with (Redis.from_url(args.redisuri, decode_responses=True) as rconn, - database_connection(args.databaseuri) as dbconn): - fqjobid = jobs.job_key(args.redisprefix, args.jobid) + with (Redis.from_url(args.redisuri, decode_responses=True) as rconn, + database_connection(args.databaseuri) as dbconn): + fqjobid = jobs.job_key(args.redisprefix, args.jobid) + + try: rconn.hset(fqjobid, "status", "started") logger.addHandler(setup_redis_logger( rconn, @@ -54,9 +55,9 @@ def build_main( return returncode rconn.hset(fqjobid, "status", "completed:error") return returncode - except Exception as _exc:# pylint: disable=[broad-except] - logger.error("The process failed!", exc_info=True) - rconn.hset(fqjobid, "status", "completed:error") - return 4 + except Exception as _exc:# pylint: disable=[broad-except] + logger.error("The process failed!", exc_info=True) + rconn.hset(fqjobid, "status", "completed:error") + return 4 return main |