mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-23 19:44:20 +00:00
Cv progress
This commit is contained in:
parent
fe73d3d897
commit
491301b681
3 changed files with 28 additions and 11 deletions
|
@ -8,7 +8,8 @@ from .errors import CommandError, \
|
||||||
UnsupportedError, \
|
UnsupportedError, \
|
||||||
ConfigurationError, \
|
ConfigurationError, \
|
||||||
ExternalError, \
|
ExternalError, \
|
||||||
UserError
|
UserError, \
|
||||||
|
ProgramError
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"CommandInterface",
|
"CommandInterface",
|
||||||
|
@ -21,5 +22,6 @@ __all__ = [
|
||||||
"ConfigurationError",
|
"ConfigurationError",
|
||||||
"ExternalError",
|
"ExternalError",
|
||||||
"UserError",
|
"UserError",
|
||||||
|
"ProgramError",
|
||||||
"Event"
|
"Event"
|
||||||
]
|
]
|
||||||
|
|
|
@ -28,3 +28,7 @@ class ConfigurationError(CommandError):
|
||||||
class ExternalError(CommandError):
|
class ExternalError(CommandError):
|
||||||
"""The command failed to execute, but the problem was because of an external factor (such as an external API going
|
"""The command failed to execute, but the problem was because of an external factor (such as an external API going
|
||||||
down)."""
|
down)."""
|
||||||
|
|
||||||
|
|
||||||
|
class ProgramError(CommandError):
|
||||||
|
"""The command encountered an error in the program."""
|
||||||
|
|
|
@ -167,8 +167,7 @@ class Serf:
|
||||||
if isinstance(response, rh.ResponseFailure):
|
if isinstance(response, rh.ResponseFailure):
|
||||||
if response.name == "no_event":
|
if response.name == "no_event":
|
||||||
raise CommandError(f"There is no event named {event_name} in {destination}.")
|
raise CommandError(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 CommandError(response.extra_info["message"])
|
raise CommandError(response.extra_info["message"])
|
||||||
elif response.extra_info["type"] == "UserError":
|
elif response.extra_info["type"] == "UserError":
|
||||||
|
@ -182,13 +181,16 @@ class Serf:
|
||||||
elif response.extra_info["type"] == "ExternalError":
|
elif response.extra_info["type"] == "ExternalError":
|
||||||
raise ExternalError(response.extra_info["message"])
|
raise ExternalError(response.extra_info["message"])
|
||||||
else:
|
else:
|
||||||
raise ValueError(f"Herald action call returned invalid error:\n"
|
raise ProgramError(f"Invalid error in Herald event '{event_name}':\n"
|
||||||
f"[p]{response}[/p]")
|
f"[p]{response}[/p]")
|
||||||
|
elif response.name == "unhandled_exception_in_event":
|
||||||
|
raise ProgramError(f"Unhandled exception in Herald event '{event_name}':\n"
|
||||||
|
f"[p]{response}[/p]")
|
||||||
elif isinstance(response, rh.ResponseSuccess):
|
elif isinstance(response, rh.ResponseSuccess):
|
||||||
return response.data
|
return response.data
|
||||||
else:
|
else:
|
||||||
raise ValueError(f"Other Herald Link returned unknown response:\n"
|
raise ProgramError(f"Other Herald Link returned unknown response:\n"
|
||||||
f"[p]{response}[/p]")
|
f"[p]{response}[/p]")
|
||||||
|
|
||||||
return GenericInterface
|
return GenericInterface
|
||||||
|
|
||||||
|
@ -266,10 +268,18 @@ class Serf:
|
||||||
try:
|
try:
|
||||||
response_data = await event.run(**message.data)
|
response_data = await event.run(**message.data)
|
||||||
return rh.ResponseSuccess(data=response_data)
|
return rh.ResponseSuccess(data=response_data)
|
||||||
|
except CommandError as e:
|
||||||
|
return rh.ResponseFailure("error_in_event",
|
||||||
|
f"The event '{message.handler}' raised a {e.__class__.__qualname__}.",
|
||||||
|
extra_info={
|
||||||
|
"type": e.__class__.__qualname__,
|
||||||
|
"message": str(e)
|
||||||
|
})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
ru.sentry_exc(e)
|
ru.sentry_exc(e)
|
||||||
return rh.ResponseFailure("exception_in_event",
|
return rh.ResponseFailure("unhandled_exception_in_event",
|
||||||
f"An exception was raised in the event for '{message.handler}'.",
|
f"The event '{message.handler}' raised an unhandled"
|
||||||
|
f" {e.__class__.__qualname__}.",
|
||||||
extra_info={
|
extra_info={
|
||||||
"type": e.__class__.__qualname__,
|
"type": e.__class__.__qualname__,
|
||||||
"message": str(e)
|
"message": str(e)
|
||||||
|
@ -293,12 +303,13 @@ class Serf:
|
||||||
await data.reply(f"⚠️ {e.message}")
|
await data.reply(f"⚠️ {e.message}")
|
||||||
except ConfigurationError as e:
|
except ConfigurationError as e:
|
||||||
await data.reply(f"⚠️ {e.message}")
|
await data.reply(f"⚠️ {e.message}")
|
||||||
|
except ProgramError as e:
|
||||||
|
await data.reply(f"⛔️ {e.message}")
|
||||||
except CommandError as e:
|
except CommandError as e:
|
||||||
await data.reply(f"⚠️ {e.message}")
|
await data.reply(f"⚠️ {e.message}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
ru.sentry_exc(e)
|
ru.sentry_exc(e)
|
||||||
error_message = f"⛔️ [b]{e.__class__.__name__}[/b]\n" + '\n'.join(e.args)
|
await data.reply(f"⛔️ [b]{e.__class__.__name__}[/b]\n" + '\n'.join(e.args))
|
||||||
await data.reply(error_message)
|
|
||||||
|
|
||||||
async def run(self):
|
async def run(self):
|
||||||
"""A coroutine that starts the event loop and handles command calls."""
|
"""A coroutine that starts the event loop and handles command calls."""
|
||||||
|
|
Loading…
Reference in a new issue