1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 19:44:20 +00:00

Fix bugs in call_herald_event

This commit is contained in:
Steffo 2020-01-12 13:51:36 +01:00
parent 1633ff006c
commit 25889fb779
3 changed files with 23 additions and 11 deletions

View file

@ -177,17 +177,16 @@ class Constellation:
constellation = self constellation = self
async def call_herald_event(ci, destination: str, event_name: str, **kwargs) -> Dict: async def call_herald_event(ci, destination: str, event_name: str, **kwargs) -> Dict:
"""Send a :class:`rh.Request` to a specific destination, and wait for a """Send a :class:`royalherald.Request` to a specific destination, and wait for a
:class:`rh.Response`.""" :class:`royalherald.Response`."""
if self.herald is None: if self.herald is None:
raise rc.UnsupportedError("`royalherald` is not enabled on this Constellation.") raise rc.UnsupportedError("`royalherald` is not enabled on this serf.")
request: rh.Request = rh.Request(handler=event_name, data=kwargs) request: rh.Request = rh.Request(handler=event_name, data=kwargs)
response: rh.Response = await self.herald.request(destination=destination, request=request) response: rh.Response = await self.herald.request(destination=destination, request=request)
if isinstance(response, rh.ResponseFailure): if isinstance(response, rh.ResponseFailure):
if response.name == "no_event": if response.name == "no_event":
raise rc.CommandError(f"There is no event named {event_name} in {destination}.") raise rc.ProgramError(f"There is no event named {event_name} in {destination}.")
elif response.name == "exception_in_event": elif response.name == "error_in_event":
# TODO: pretty sure there's a better way to do this
if response.extra_info["type"] == "CommandError": if response.extra_info["type"] == "CommandError":
raise rc.CommandError(response.extra_info["message"]) raise rc.CommandError(response.extra_info["message"])
elif response.extra_info["type"] == "UserError": elif response.extra_info["type"] == "UserError":
@ -201,12 +200,21 @@ class Constellation:
elif response.extra_info["type"] == "ExternalError": elif response.extra_info["type"] == "ExternalError":
raise rc.ExternalError(response.extra_info["message"]) raise rc.ExternalError(response.extra_info["message"])
else: else:
raise TypeError(f"Herald action call returned invalid error:\n" raise rc.ProgramError(f"Invalid error in Herald event '{event_name}':\n"
f"[b]{response.extra_info['type']}[/b]\n"
f"{response.extra_info['message']}")
elif response.name == "unhandled_exception_in_event":
raise rc.ProgramError(f"Unhandled exception in Herald event '{event_name}':\n"
f"[b]{response.extra_info['type']}[/b]\n"
f"{response.extra_info['message']}")
else:
raise rc.ProgramError(f"Unknown response in Herald event '{event_name}':\n"
f"[b]{response.name}[/b]"
f"[p]{response}[/p]") f"[p]{response}[/p]")
elif isinstance(response, rh.ResponseSuccess): elif isinstance(response, rh.ResponseSuccess):
return response.data return response.data
else: else:
raise TypeError(f"Other Herald Link returned unknown response:\n" raise rc.ProgramError(f"Other Herald Link returned unknown response:\n"
f"[p]{response}[/p]") f"[p]{response}[/p]")
return GenericInterface return GenericInterface

View file

@ -188,6 +188,10 @@ class Serf:
raise ProgramError(f"Unhandled exception in Herald event '{event_name}':\n" raise ProgramError(f"Unhandled exception in Herald event '{event_name}':\n"
f"[b]{response.extra_info['type']}[/b]\n" f"[b]{response.extra_info['type']}[/b]\n"
f"{response.extra_info['message']}") f"{response.extra_info['message']}")
else:
raise ProgramError(f"Unknown response in Herald event '{event_name}':\n"
f"[b]{response.name}[/b]"
f"[p]{response}[/p]")
elif isinstance(response, rh.ResponseSuccess): elif isinstance(response, rh.ResponseSuccess):
return response.data return response.data
else: else:

View file

@ -1 +1 @@
semantic = "5.2.2" semantic = "5.2.4"