Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/roswire/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

Expand Down
12 changes: 11 additions & 1 deletion src/roswire/proxy/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 = '{}'
Expand All @@ -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:
Expand Down