Skip to content

Commit

Permalink
Update exception handling to catch more common errors
Browse files Browse the repository at this point in the history
  • Loading branch information
AC-Dap committed Dec 21, 2023
1 parent aeae5ae commit ea26754
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions ersilia/core/tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import tempfile
import logging
import boto3
from botocore.exceptions import ClientError
from botocore.exceptions import ClientError, NoCredentialsError
import os

PERSISTENT_FILE_PATH = os.path.abspath("current_session.txt")
Expand All @@ -17,15 +17,18 @@ def log_files_metrics(file):
error_count = 0
warning_count = 0

with open(file, "r") as file:
for line in file:
if "| ERROR" in line:
error_count += 1
elif "| WARNING" in line:
warning_count += 1
try:
with open(file, "r") as file:
for line in file:
if "| ERROR" in line:
error_count += 1
elif "| WARNING" in line:
warning_count += 1

write_persistent_file(f"Error count: {error_count}")
write_persistent_file(f"Warning count: {warning_count}")
write_persistent_file(f"Error count: {error_count}")
write_persistent_file(f"Warning count: {warning_count}")
except FileNotFoundError:
logging.warning("Log file not found")


def read_csv(file):
Expand Down Expand Up @@ -89,6 +92,8 @@ def upload_to_s3(json_dict, bucket="t4sg-ersilia", object_name=None):
s3_client = boto3.client("s3")
try:
s3_client.upload_file(tmp.name, bucket, f"{object_name}.json")
except NoCredentialsError:
logging.error("Unable to upload tracking data to AWS: Credentials not found")
except ClientError as e:
logging.error(e)
return False
Expand Down

0 comments on commit ea26754

Please sign in to comment.