Skip to content

Commit

Permalink
more error checking and better exception hygiene
Browse files Browse the repository at this point in the history
  • Loading branch information
mahmoud committed Mar 5, 2016
1 parent b253411 commit 5b85f92
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
2 changes: 2 additions & 0 deletions lithoxyl/actors.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ def __init__(self, task, interval=DEFAULT_INTERVAL, **kwargs):
self.max_interval = float(max_interval or interval * 8)
self._daemonize_thread = kwargs.pop('daemonize_thread', True)
self._note = kwargs.pop('note', None)
if not callable(self._note):
raise ValueError('expected callable for note, not %r' % self._note)
if kwargs:
raise TypeError('unexpected keyword arguments: %r' % kwargs.keys())

Expand Down
4 changes: 2 additions & 2 deletions lithoxyl/ewma.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ def __init__(self, periods=None, interval=None):
"Takes an iterable of periods and an update interval, both in seconds."
self._interval = float(interval or DEFAULT_INTERVAL)
if not self._interval > 0:
raise TypeError('interval must be greater than 0, not: %r'
% self._interval)
raise ValueError('interval must be greater than 0, not: %r'
% self._interval)

periods = periods or DEFAULT_PERIODS
self._rate_map = dict([(p, None) for p in periods])
Expand Down
7 changes: 2 additions & 5 deletions lithoxyl/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,7 @@ def __repr__(self):

@property
def level_name(self):
try:
return self.level.name
except Exception:
return repr(self.level)
return self.level.name

@property
def status(self):
Expand All @@ -117,7 +114,7 @@ def duration(self):
try:
return self.complete_record.ctime - self.begin_record.ctime
except Exception:
return 0
return 0.0

def begin(self, message=None, *a, **kw):
self.data_map.update(kw)
Expand Down

0 comments on commit 5b85f92

Please sign in to comment.