Skip to content

Commit

Permalink
Fix raise error convention
Browse files Browse the repository at this point in the history
  • Loading branch information
Walter C. Pettus committed Dec 6, 2024
1 parent b8c6301 commit f4dbbe6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
6 changes: 2 additions & 4 deletions dripline/core/calibrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
# optional only when doing a docs build
pass

#TODO need to put exceptions back, this is fragile/wrong right now
#from . import exceptions


__all__ = []
Expand Down Expand Up @@ -47,15 +45,15 @@ def wrapper(self, *args, **kwargs):
logger.debug('GOT AN OVERFLOW ERROR')
cal = None
except Exception as e:
raise exceptions.DriplineValueError(repr(e), result=val_dict)
raise ValueError(repr(e))
if cal is not None:
val_dict['value_cal'] = cal
elif isinstance(self._calibration, dict):
logger.debug('calibration is dictionary, looking up value')
if val_dict['value_raw'] in self._calibration:
val_dict['value_cal'] = self._calibration[val_dict['value_raw']]
else:
raise exceptions.DriplineValueError(f"raw value <{repr(val_dict['value_raw'])}> not in cal dict", result=val_dict)
raise ValueError(f"raw value <{repr(val_dict['value_raw'])}> not in cal dict)
else:
logger.warning('the _calibration property is of unknown type')
return val_dict
Expand Down
5 changes: 2 additions & 3 deletions dripline/implementations/entity_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,15 @@ def on_get(self):
matches = re.search(self._extract_raw_regex, first_result)
if matches is None:
logger.error('matching returned none')
# exceptions.DriplineValueError
raise ThrowReply('resource_error', 'device returned unparsable result, [{}] has no match to input regex [{}]'.format(first_result, self._extract_raw_regex))
raise ValueError('device returned unparsable result, [{}] has no match to input regex [{}]'.format(first_result, self._extract_raw_regex))
logger.debug(f"matches are: {matches.groupdict()}")
result = matches.groupdict()['value_raw']
return result

def on_set(self, value):
if self._set_str is None:
# exceptions.DriplineMethodNotSupportedError
raise ThrowReply('service_error', f"endpoint '{self.name}' does not support set")
raise ThrowReply('message_error_invalid_method', f"endpoint '{self.name}' does not support set")
if isinstance(value, str) and self._set_value_lowercase:
value = value.lower()
if self._set_value_map is None:
Expand Down

0 comments on commit f4dbbe6

Please sign in to comment.