Skip to content

Commit

Permalink
Fix exception messages (#1113)
Browse files Browse the repository at this point in the history
Fix PynamoDBException-derived exceptions that define their message as a class variable.
  • Loading branch information
pauliokas committed Nov 16, 2022
1 parent cdb36d0 commit 4e7054d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 3 additions & 1 deletion pynamodb/exceptions.py
Expand Up @@ -8,11 +8,13 @@


class PynamoDBException(Exception):
msg: str

"""
A common exception class
"""
def __init__(self, msg: Optional[str] = None, cause: Optional[Exception] = None) -> None:
self.msg = msg
self.msg = msg if msg is not None else self.msg
self.cause = cause
super(PynamoDBException, self).__init__(self.msg)

Expand Down
9 changes: 8 additions & 1 deletion tests/test_exceptions.py
@@ -1,6 +1,6 @@
from botocore.exceptions import ClientError

from pynamodb.exceptions import PutError
from pynamodb.exceptions import PynamoDBException, PutError


def test_get_cause_response_code():
Expand Down Expand Up @@ -40,3 +40,10 @@ def test_get_cause_response_message__no_message():
error = PutError()
assert error.cause_response_message is None


class PynamoDBTestError(PynamoDBException):
msg = "Test message"


def test_subclass_message_is_not_overwritten_with_none():
assert PynamoDBTestError().msg == "Test message"

0 comments on commit 4e7054d

Please sign in to comment.