diff --git a/helpers/exceptions.py b/helpers/exceptions.py index 94d241b73..5e4c8b6dd 100644 --- a/helpers/exceptions.py +++ b/helpers/exceptions.py @@ -1,5 +1,7 @@ class ReportExpiredException(Exception): - pass + def __init__(self, message=None, filename=None) -> None: + super().__init__(message) + self.filename = filename class ReportEmptyError(Exception): diff --git a/services/report/__init__.py b/services/report/__init__.py index 914e73e90..20e04afb8 100644 --- a/services/report/__init__.py +++ b/services/report/__init__.py @@ -1016,11 +1016,16 @@ def build_report_from_raw_content( raw_report=result.raw_report, upload_obj=upload, ) - except ReportExpiredException: + except ReportExpiredException as r: log.info( "Report %s is expired", reportid, - extra=dict(repoid=commit.repoid, commit=commit.commitid), + extra=dict( + repoid=commit.repoid, + commit=commit.commitid, + archive_path=archive_url, + file_name=r.filename, + ), ) return ProcessingResult( report=None, diff --git a/services/report/raw_upload_processor.py b/services/report/raw_upload_processor.py index c9146d592..2a67fafa0 100644 --- a/services/report/raw_upload_processor.py +++ b/services/report/raw_upload_processor.py @@ -11,7 +11,7 @@ from shared.utils.sessions import Session, SessionType from database.models.reports import Upload -from helpers.exceptions import ReportEmptyError +from helpers.exceptions import ReportEmptyError, ReportExpiredException from helpers.labels import get_all_report_labels, get_labels_per_session from rollouts import USE_LABEL_INDEX_IN_REPORT_PROCESSING_BY_REPO_ID from services.path_fixer import PathFixer @@ -155,9 +155,13 @@ def process_raw_upload( path_fixer_to_use, should_use_encoded_labels, ) - report = process_report( - report=report_file, report_builder=report_builder_to_use - ) + try: + report = process_report( + report=report_file, report_builder=report_builder_to_use + ) + except ReportExpiredException as r: + r.filename = current_filename + raise if report: if should_use_encoded_labels: # Copies the labels from report into temporary_report diff --git a/services/report/tests/unit/test_process.py b/services/report/tests/unit/test_process.py index 425fb05d6..7ef6c6737 100644 --- a/services/report/tests/unit/test_process.py +++ b/services/report/tests/unit/test_process.py @@ -11,7 +11,11 @@ from shared.utils.sessions import Session, SessionType from shared.yaml import UserYaml -from helpers.exceptions import CorruptRawReportError, ReportEmptyError +from helpers.exceptions import ( + CorruptRawReportError, + ReportEmptyError, + ReportExpiredException, +) from services.report import raw_upload_processor as process from services.report.parser import LegacyReportParser from services.report.parser.types import LegacyParsedRawReport, ParsedUploadedReportFile @@ -984,6 +988,38 @@ def test_process_raw_upload_multiple_raw_reports(self, mocker): assert sorted(res.sessions.keys()) == [0, 1] assert res.sessions[1] == session + def test_process_raw_upload_expired_report(self, mocker): + filename = "/Users/path/to/app.coverage.txt" + uploaded_reports = LegacyParsedRawReport( + toc=None, + env=None, + report_fixes=None, + uploaded_files=[ + ParsedUploadedReportFile( + filename="/Users/path/to/app.coverage.txt", + file_contents=BytesIO("".encode()), + ), + ], + ) + mocker.patch.object( + process, + "process_report", + side_effect=[ + ReportExpiredException(), + ], + ) + session = Session() + with pytest.raises(ReportExpiredException) as e: + _ = process.process_raw_upload( + UserYaml({}), + None, + uploaded_reports, + ["flag_one", "flag_two"], + session=session, + ) + + assert e.value.filename == filename + class TestProcessRawUploadCarryforwardFlags(BaseTestCase): def _generate_sample_report(self) -> EditableReport: