mirror of
https://github.com/lowobservable/oec.git
synced 2026-01-11 23:53:04 +00:00
Improve aggregate execute error message
This commit is contained in:
parent
f7dffe6ea3
commit
f12625732c
@ -11,9 +11,14 @@ from coax import ReceiveTimeout
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
class AggregateExecuteError(Exception):
|
||||
class ExecuteError(Exception):
|
||||
def __init__(self, errors, responses):
|
||||
super().__init__('One or more errors occurred')
|
||||
if len(errors) == 1:
|
||||
message = str(errors[0])
|
||||
else:
|
||||
message = f'{len(errors)} occurred'
|
||||
|
||||
super().__init__(message)
|
||||
|
||||
self.errors = errors
|
||||
self.responses = responses
|
||||
@ -44,14 +49,16 @@ class InterfaceWrapper:
|
||||
return self.interface.execute(commands, self.timeout)
|
||||
|
||||
responses = self.interface.execute(commands, self.timeout)
|
||||
|
||||
errors = [response for response in responses if isinstance(response, BaseException) and (receive_timeout_is_error or not isinstance(response, ReceiveTimeout))]
|
||||
errors = get_errors(responses, receive_timeout_is_error)
|
||||
|
||||
if any(errors):
|
||||
raise AggregateExecuteError(errors, responses)
|
||||
raise ExecuteError(errors, responses)
|
||||
|
||||
return responses
|
||||
|
||||
def get_errors(responses, receive_timeout_is_error):
|
||||
return [response for response in responses if isinstance(response, BaseException) and (receive_timeout_is_error or not isinstance(response, ReceiveTimeout))]
|
||||
|
||||
def _get_jumbo_write_strategy():
|
||||
value = os.environ.get('COAX_JUMBO')
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@ from coax import ReadAddressCounterHi, ReadAddressCounterLo, ProtocolError
|
||||
|
||||
import context
|
||||
|
||||
from oec.interface import InterfaceWrapper, AggregateExecuteError
|
||||
from oec.interface import InterfaceWrapper, ExecuteError
|
||||
|
||||
from mock_interface import MockInterface
|
||||
|
||||
@ -96,7 +96,7 @@ class InterfaceWrapperExecuteTestCase(unittest.TestCase):
|
||||
]
|
||||
|
||||
# Act and assert
|
||||
with self.assertRaises(AggregateExecuteError) as context:
|
||||
with self.assertRaises(ExecuteError) as context:
|
||||
self.interface_wrapper.execute([(None, ReadAddressCounterHi()), (None, ReadAddressCounterLo())])
|
||||
|
||||
error = context.exception
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user