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

Add exceptions #138

Merged
merged 3 commits into from
Feb 3, 2021
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
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
mkdir -p ~/.virtualenvs
python3 -m venv ~/.virtualenvs/singer-python
source ~/.virtualenvs/singer-python/bin/activate
pip install -U pip setuptools
pip install -U 'pip<19.2' 'setuptools<51.0.0'
make install
- run:
name: 'Run tests'
Expand Down
8 changes: 8 additions & 0 deletions singer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@
get_currently_syncing,
)

from singer.exceptions import (
SingerConfigurationError,
SingerDiscoveryError,
SingerError,
SingerRetryableRequestError,
SingerSyncError,
)

if __name__ == "__main__":
import doctest
doctest.testmod()
30 changes: 30 additions & 0 deletions singer/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""
The exceptions module contains Exception subclasses whose instances might be
raised by the singer library or taps that use the singer library.
"""

class SingerError(Exception):
"""The base Exeception class for singer"""
def __init__(self, message):
"""Create an exeception with a multiline error message

The first line is the error's class name. The subsequent lines are
the message that class was created with.
"""
super().__init__('{}\n{}'.format(self.__class__.__name__, message))


class SingerConfigurationError(SingerError):
"""The base class of errors encountered before discovery and before sync mode"""


class SingerDiscoveryError(SingerError):
"""The base class of errors encountered in discovery mode"""


class SingerSyncError(SingerError):
"""The base class of errors encountered in sync mode"""


class SingerRetryableRequestError(SingerError):
"""This error is meant to be thrown when a tap encounters a retryable request"""
68 changes: 68 additions & 0 deletions tests/test_exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import unittest

from singer.exceptions import SingerConfigurationError
from singer.exceptions import SingerDiscoveryError
from singer.exceptions import SingerError
from singer.exceptions import SingerRetryableRequestError
from singer.exceptions import SingerSyncError

class TestSingerErrors(unittest.TestCase):
def test_SingerError_prints_correctly(self):
error_text = "An error occured"

with self.assertRaises(SingerError) as test_run:
raise SingerError(error_text)

expected_text = "SingerError\n" + error_text
self.assertEquals(expected_text,
str(test_run.exception))

def test_SingerConfigurationError_prints_correctly(self):
error_text = "An error occured"

with self.assertRaises(SingerConfigurationError) as test_run:
raise SingerConfigurationError(error_text)

expected_text = "SingerConfigurationError\n" + error_text
self.assertEquals(expected_text,
str(test_run.exception))

def test_SingerDiscoveryError_prints_correctly(self):
error_text = "An error occured"

with self.assertRaises(SingerDiscoveryError) as test_run:
raise SingerDiscoveryError(error_text)

expected_text = "SingerDiscoveryError\n" + error_text
self.assertEquals(expected_text,
str(test_run.exception))

def test_SingerSyncError_prints_correctly(self):
error_text = "An error occured"

with self.assertRaises(SingerSyncError) as test_run:
raise SingerSyncError(error_text)

expected_text = "SingerSyncError\n" + error_text
self.assertEquals(expected_text,
str(test_run.exception))

def test_SingerRetryableRequestError_prints_correctly(self):
error_text = "An error occured"

with self.assertRaises(SingerRetryableRequestError) as test_run:
raise SingerRetryableRequestError(error_text)

expected_text = "SingerRetryableRequestError\n" + error_text
self.assertEquals(expected_text,
str(test_run.exception))

def test_SingerError_prints_multiple_lines_correctly(self):
error_text = "\n".join(["Line 1", "Line 2", "Line 3"])

with self.assertRaises(SingerError) as test_run:
raise SingerError(error_text)

expected_text = "SingerError\n" + error_text
self.assertEquals(expected_text,
str(test_run.exception))