-
Notifications
You must be signed in to change notification settings - Fork 403
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: batch processing exceptions (#276)
* fix: Add tracebacks for all caught exceptions to SQSBatchProcessingError output * chore: Remove debugging code * chore: fix unit test to account for change in exception passing * chore: use kwargs in method calls, add comment to SQSBatchProcessingError * chore: Fix tests after changing method calls to use kwargs
- Loading branch information
Tom McCarthy
authored
Feb 2, 2021
1 parent
575a103
commit be6aa08
Showing
5 changed files
with
45 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,25 @@ | ||
""" | ||
Batch processing exceptions | ||
""" | ||
import traceback | ||
|
||
|
||
class SQSBatchProcessingError(Exception): | ||
"""When at least one message within a batch could not be processed""" | ||
|
||
def __init__(self, msg="", child_exceptions=()): | ||
super().__init__(msg) | ||
self.msg = msg | ||
self.child_exceptions = child_exceptions | ||
|
||
# Overriding this method so we can output all child exception tracebacks when we raise this exception to prevent | ||
# errors being lost. See https://github.com/awslabs/aws-lambda-powertools-python/issues/275 | ||
def __str__(self): | ||
parent_exception_str = super(SQSBatchProcessingError, self).__str__() | ||
exception_list = [f"{parent_exception_str}\n"] | ||
for exception in self.child_exceptions: | ||
extype, ex, tb = exception | ||
formatted = "".join(traceback.format_exception(extype, ex, tb)) | ||
exception_list.append(formatted) | ||
|
||
return "\n".join(exception_list) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters