Skip to content

Commit

Permalink
Merge pull request #23 from yarikoptic/enh-exc
Browse files Browse the repository at this point in the history
ENH: dedicated BadVersionError to raise if bad version detected
  • Loading branch information
satra authored Aug 5, 2020
2 parents 5115137 + fa9a06c commit ca72400
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions etelemetry/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
_available_version_checked = None


class BadVersionError(RuntimeError):
"""Local version is known to contain a critical bug etc."""
pass


def _etrequest(endpoint, method="get", **kwargs):
if kwargs.get('timeout') is None:
kwargs['timeout'] = 5
Expand Down Expand Up @@ -65,6 +70,7 @@ def get_project(repo, **rargs):
def check_available_version(project, version, lgr=None, raise_exception=False):
"""A helper to check (and report) if newer version of project is available
Should be ok to execute multiple times, it will be checked only one time
Parameters
----------
project: str
Expand All @@ -74,7 +80,7 @@ def check_available_version(project, version, lgr=None, raise_exception=False):
lgr: python logger object
external logger to be used
raise_exception: bool
raise an exception if a bad local version is detected
raise a BadVersionError exception if a bad local version is detected
"""
global _available_version_checked
if _available_version_checked is not None:
Expand Down Expand Up @@ -117,7 +123,7 @@ def check_available_version(project, version, lgr=None, raise_exception=False):
message = ("You are using a version of {0} with a critical bug. "
"Please use a different version.").format(project)
if raise_exception:
raise RuntimeError(message)
raise BadVersionError(message)
else:
lgr.critical(message)
_available_version_checked = latest
Expand Down

0 comments on commit ca72400

Please sign in to comment.