From 85ae96a10dc3fed6942103c1d69150b8f9d61f30 Mon Sep 17 00:00:00 2001 From: Mike VanDenburgh Date: Wed, 18 Dec 2024 15:28:49 -0500 Subject: [PATCH] Make distinction between no artifacts vs missing file Failed jobs will frequently have *no artifacts*. This change introduces a new exception type to distinguish between no artifacts and missing artifacts. --- analytics/analytics/job_processor/artifacts.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/analytics/analytics/job_processor/artifacts.py b/analytics/analytics/job_processor/artifacts.py index 2e3a42d15..0a9357478 100644 --- a/analytics/analytics/job_processor/artifacts.py +++ b/analytics/analytics/job_processor/artifacts.py @@ -8,6 +8,12 @@ from gitlab.v4.objects import ProjectJob +class JobHasNoArtifacts(Exception): + def __init__(self, job: ProjectJob) -> None: + message = f"Job {job.id} has no artifacts" + super().__init__(message) + + class JobArtifactFileNotFound(Exception): def __init__(self, job: ProjectJob, filename: str): message = f"File {filename} not found in job artifacts of job {job.id}" @@ -37,7 +43,7 @@ def get_job_artifacts_file(job: ProjectJob, filename: str): with open(artifacts_file, "wb") as f: job.artifacts(streamed=True, action=f.write) except GitlabGetError: - raise JobArtifactFileNotFound(job, filename) + raise JobHasNoArtifacts(job) # Open specific file within artifacts zip with zipfile.ZipFile(artifacts_file) as zfile: