Skip to content
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
22 changes: 20 additions & 2 deletions src/s3_encryption/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,24 @@
This module contains custom exception classes used throughout the S3 Encryption Client.
"""

from botocore.exceptions import BotoCoreError

class S3EncryptionClientError(Exception):
"""Exception class for S3 Encryption Client errors."""

class S3EncryptionClientError(BotoCoreError):
"""Exception class for non-Security S3 Encryption Client errors."""

fmt = "{msg}"

def __init__(self, message="An unspecified S3 Encryption Client error occurred"):
"""Initialize the exception with a message."""
super().__init__(msg=message)


class S3EncryptionClientSecurityError(BotoCoreError):
"""Security Exceptions for S3 Encryption Client errors."""

fmt = "{msg}"

def __init__(self, message="An unspecified S3 Encryption Client Security error occurred"):
"""Initialize the exception with a message."""
super().__init__(msg=message)
51 changes: 51 additions & 0 deletions test/test_exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import pytest
from botocore.exceptions import BotoCoreError

from s3_encryption.exceptions import (
S3EncryptionClientError,
S3EncryptionClientSecurityError,
)


class TestS3EncryptionClientError:
def test_default_message(self):
error = S3EncryptionClientError()
assert str(error) == "An unspecified S3 Encryption Client error occurred"

def test_custom_message(self):
error = S3EncryptionClientError("Custom error message")
assert str(error) == "Custom error message"

def test_empty_message(self):
error = S3EncryptionClientError("")
assert str(error) == ""

def test_inherits_from_botocore_error(self):
error = S3EncryptionClientError("test")
assert isinstance(error, BotoCoreError)

def test_can_be_caught_as_botocore_error(self):
with pytest.raises(BotoCoreError):
raise S3EncryptionClientError("test error")


class TestS3EncryptionClientSecurityError:
def test_default_message(self):
error = S3EncryptionClientSecurityError()
assert str(error) == "An unspecified S3 Encryption Client Security error occurred"

def test_custom_message(self):
error = S3EncryptionClientSecurityError("Custom security error")
assert str(error) == "Custom security error"

def test_empty_message(self):
error = S3EncryptionClientSecurityError("")
assert str(error) == ""

def test_inherits_from_botocore_error(self):
error = S3EncryptionClientSecurityError("test")
assert isinstance(error, BotoCoreError)

def test_can_be_caught_as_botocore_error(self):
with pytest.raises(BotoCoreError):
raise S3EncryptionClientSecurityError("test security error")