From dba0b22073a36eb17c55e6d358df694cf92aab39 Mon Sep 17 00:00:00 2001 From: Kian-Tat Lim Date: Sun, 6 Oct 2024 14:36:37 -0700 Subject: [PATCH] Return exception message on open fail. --- python/s3daemon/s3daemon.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/python/s3daemon/s3daemon.py b/python/s3daemon/s3daemon.py index 7409110..97b9333 100644 --- a/python/s3daemon/s3daemon.py +++ b/python/s3daemon/s3daemon.py @@ -77,14 +77,14 @@ async def handle_client(client, reader, writer): start = time.time() # ignore the alias _, bucket, key = dest.split("/", maxsplit=2) - with open(filename, "rb") as f: - try: + try: + with open(filename, "rb") as f: await client.put_object(Body=f, Bucket=bucket, Key=key) writer.write(b"Success") log.info("%f %f sec - %s", start, time.time() - start, filename) - except Exception as e: - writer.write(bytes(repr(e), "UTF-8")) - log.exception("%f %f sec - %s", start, time.time() - start, filename) + except Exception as e: + writer.write(bytes(repr(e), "UTF-8")) + log.exception("%f %f sec - %s", start, time.time() - start, filename) async def go():