From a53fb391cc9aa3f2f89a35ae8ef6feb06870b385 Mon Sep 17 00:00:00 2001 From: ChrisTimperley Date: Tue, 5 Nov 2019 16:12:42 -0500 Subject: [PATCH 1/2] created UnexpectedServiceCallError exception --- src/roswire/exceptions.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/roswire/exceptions.py b/src/roswire/exceptions.py index 1ce3ba490..1443db57e 100644 --- a/src/roswire/exceptions.py +++ b/src/roswire/exceptions.py @@ -6,6 +6,30 @@ class ROSWireException(Exception): """Base class used by all ROSWire exceptions.""" +@_attr.s(frozen=True, auto_exc=True, auto_attribs=True) +class UnexpectedServiceCallError(ROSWireException): + """An unexpected error occurred during a service call. + + Attributes + ---------- + service_name: str + The name of the service that was called. + retcode: int + The return code that was produced by rosservice. + output: str + The output that was produced by rosservice + """ + service_name: str + retcode: int + output: str + + def __str__(self) -> str: + m = (f"Unexpected exit code [{self.retcode}] occurred " + f" during call to service [{self.service_name}]. " + f"Produced output: \"{self.output}\"") + return m + + class FailedToParseLaunchFile(ROSWireException): """An attempt to parse a launch file failed.""" From 6b7713439cfd9f05b65cc24e6f4511d479b5c057 Mon Sep 17 00:00:00 2001 From: ChrisTimperley Date: Tue, 5 Nov 2019 16:14:34 -0500 Subject: [PATCH 2/2] updated service proxy to use new exception --- src/roswire/proxy/service.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/roswire/proxy/service.py b/src/roswire/proxy/service.py index bee08c0d6..278647dce 100644 --- a/src/roswire/proxy/service.py +++ b/src/roswire/proxy/service.py @@ -13,6 +13,7 @@ from .shell import ShellProxy from .. import exceptions +from ..exceptions import UnexpectedServiceCallError from ..definitions import Message, SrvFormat, MsgFormat from ..description import SystemDescription @@ -51,6 +52,13 @@ def call(self, message: Optional[Message] = None) -> Optional[Message]: ------- Optional[Message] The reply produced by the service, if any. + + Raises + ------ + ROSWireException + If illegal arguments are provided to the service call. + UnexpectedServiceCallError + If an unexpected error occurred during the service call. """ if not message: yml = '{}' @@ -62,7 +70,9 @@ def call(self, message: Optional[Message] = None) -> Optional[Message]: if code == 2: raise exceptions.ROSWireException('illegal service call args') if code != 0: - raise exceptions.ROSWireException('unexpected error during service call') # noqa + raise UnexpectedServiceCallError(service_name=self.name, + retcode=code, + output=output) fmt_response: Optional[MsgFormat] = self.format.response if not fmt_response: