Skip to content

Commit

Permalink
Don't crash in case of unexpected build date format
Browse files Browse the repository at this point in the history
try to parse the date, if unsuccessful, give up instead of crashing
entirely
  • Loading branch information
Michael Grifalconi committed Apr 29, 2024
1 parent 13f1e14 commit ad50b4c
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions openqabot/approver.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,12 @@ def was_ok_before(self, failed_job_id: int, inc: int) -> bool:
return False

current_build = older_jobs["data"][0]["build"][:-2]
current_build_date = datetime.strptime(current_build, "%Y%m%d")
try:
current_build_date = datetime.strptime(current_build, "%Y%m%d")
except (ValueError, TypeError):
log.info("Could not parse build date %s", current_build)
return False


# Use at most X days old build. Don't go back in time too much to reduce risk of using invalid tests
oldest_build_usable = current_build_date - timedelta(
Expand All @@ -177,7 +182,11 @@ def was_ok_before(self, failed_job_id: int, inc: int) -> bool:
for i in range(1, len(older_jobs["data"])):
job = older_jobs["data"][i]
job_build = job["build"][:-2]
job_build_date = datetime.strptime(job_build, "%Y%m%d")
try:
job_build_date = datetime.strptime(job_build, "%Y%m%d")
except (ValueError, TypeError):
log.info("Could not parse build date %s", current_build)
continue

# Check the job is not too old
if job_build_date < oldest_build_usable:
Expand Down

0 comments on commit ad50b4c

Please sign in to comment.