Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: exception logging #253

Merged
merged 4 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions src/sbl_filing_api/services/submission_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,13 @@ async def validate_and_update_submission(

await update_submission(session, submission)

except RuntimeError as re:
log.error("The file is malformed", re, exc_info=True, stack_info=True)
except RuntimeError:
log.exception("The file is malformed.")
submission.state = SubmissionState.SUBMISSION_UPLOAD_MALFORMED
await update_submission(session, submission)

except Exception as e:
log.error(
f"Validation for submission {submission.id} did not complete due to an unexpected error.",
e,
exc_info=True,
stack_info=True,
)
except Exception:
log.exception("Validation for submission %d did not complete due to an unexpected error.", submission.id)
submission.state = SubmissionState.VALIDATION_ERROR
await update_submission(session, submission)

Expand Down
15 changes: 12 additions & 3 deletions tests/services/test_submission_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from http import HTTPStatus
from sbl_filing_api.services import submission_processor
from fastapi import HTTPException
from unittest.mock import Mock, ANY
from unittest.mock import Mock
from pytest_mock import MockerFixture
from sbl_filing_api.config import settings
from sbl_filing_api.entities.models.dao import SubmissionDAO, SubmissionState
Expand Down Expand Up @@ -196,7 +196,7 @@ async def test_validate_and_update_submission_malformed(
)

mock_update_submission.assert_called()
log_mock.error.assert_called_with("The file is malformed", ANY, exc_info=True, stack_info=True)
log_mock.exception.assert_called_with("The file is malformed.")

assert mock_update_submission.mock_calls[0].args[1].state == SubmissionState.VALIDATION_IN_PROGRESS
assert mock_update_submission.mock_calls[1].args[1].state == SubmissionState.SUBMISSION_UPLOAD_MALFORMED
Expand All @@ -208,10 +208,19 @@ async def test_validate_and_update_submission_malformed(
await submission_processor.validate_and_update_submission(
"2024", "123456790", mock_sub, None, {"continue": True}
)
log_mock.error.assert_called_with("The file is malformed", ANY, exc_info=True, stack_info=True)
log_mock.exception.assert_called_with("The file is malformed.")
assert mock_update_submission.mock_calls[0].args[1].state == SubmissionState.VALIDATION_IN_PROGRESS
assert mock_update_submission.mock_calls[1].args[1].state == SubmissionState.SUBMISSION_UPLOAD_MALFORMED

mock_validation.side_effect = Exception("Test exception")

await submission_processor.validate_and_update_submission(
"2024", "123456790", mock_sub, None, {"continue": True}
)
log_mock.exception.assert_called_with(
"Validation for submission %d did not complete due to an unexpected error.", mock_sub.id
)

async def test_validation_expired(
self,
mocker: MockerFixture,
Expand Down
Loading