"EventsResultsError"->"EventResultsError", move errors to utils.error

This commit is contained in:
jesopo 2019-11-18 12:06:59 +00:00
parent 4ba4a8ad76
commit 9c4902dcfe
20 changed files with 35 additions and 33 deletions

View file

@ -16,4 +16,4 @@ class Module(ModuleManager.BaseModule):
acronyms.append(element.expan.string)
event["stdout"].write("%s: %s" % (query, ", ".join(acronyms)))
else:
raise utils.EventsResultsError()
raise utils.EventResultsError()

View file

@ -24,4 +24,4 @@ class Module(ModuleManager.BaseModule):
event["stderr"].write("Unknown currency, available "
"currencies: %s" % ", ".join(page.data.keys()))
else:
raise utils.EventsResultsError()
raise utils.EventResultsError()

View file

@ -46,7 +46,7 @@ class Module(ModuleManager.BaseModule):
else:
event["stderr"].write("No definitions found")
else:
raise utils.EventsResultsError()
raise utils.EventResultsError()
@utils.hook("received.command.randomword")
def random_word(self, event):
@ -69,6 +69,6 @@ class Module(ModuleManager.BaseModule):
event["stdout"].write("Random Word: %s - Definition: %s" % (
page.data["word"], text))
else:
raise utils.EventsResultsError()
raise utils.EventResultsError()
else:
event["stderr"].write("Try again in a couple of seconds")

View file

@ -38,7 +38,7 @@ class Module(ModuleManager.BaseModule):
else:
event["stderr"].write("No results found")
else:
raise utils.EventsResultsError()
raise utils.EventResultsError()
else:
event["stderr"].write("No phrase provided")
@ -65,6 +65,6 @@ class Module(ModuleManager.BaseModule):
else:
event["stderr"].write("No suggestions found")
else:
raise utils.EventsResultsError()
raise utils.EventResultsError()
else:
event["stderr"].write("No phrase provided")

View file

@ -29,4 +29,4 @@ class Module(ModuleManager.BaseModule):
else:
event["stderr"].write("Title not found")
else:
raise utils.EventsResultsError()
raise utils.EventResultsError()

View file

@ -153,4 +153,4 @@ class Module(ModuleManager.BaseModule):
if result:
event["stdout"].write(result)
else:
raise utils.EventsResultsError()
raise utils.EventResultsError()

View file

@ -102,7 +102,7 @@ class Module(ModuleManager.BaseModule):
else:
event["stderr"].write("No geoip data found")
else:
raise utils.EventsResultsError()
raise utils.EventResultsError()
@utils.hook("received.command.rdns")
def rdns(self, event):

View file

@ -96,4 +96,4 @@ class Module(ModuleManager.BaseModule):
"The user '%s' has never scrobbled before" % (
shown_username))
else:
raise utils.EventsResultsError()
raise utils.EventResultsError()

View file

@ -14,7 +14,7 @@ def _get_relays_details(search):
URL_ONIONOO_DETAILS, get_params={"search": search}, json=True)
if page and "relays" in page.data:
return page.data["relays"]
raise utils.EventsResultsError()
raise utils.EventResultsError()
def _format_relay_summary_message(relays, search):
if len(relays) > 1:

View file

@ -62,4 +62,4 @@ class Module(ModuleManager.BaseModule):
else:
event["stderr"].write("No results found")
else:
raise utils.EventsResultsError()
raise utils.EventResultsError()

View file

@ -55,4 +55,4 @@ class Module(ModuleManager.BaseModule):
else:
event["stderr"].write("No results found")
else:
raise utils.EventsResultsError()
raise utils.EventResultsError()

View file

@ -46,4 +46,4 @@ class Module(ModuleManager.BaseModule):
else:
event["stderr"].write("Category not found")
else:
raise utils.EventsResultsError()
raise utils.EventResultsError()

View file

@ -56,4 +56,4 @@ class Module(ModuleManager.BaseModule):
event["stderr"].write(
"%s is not watching anything" % username)
else:
raise utils.EventsResultsError()
raise utils.EventResultsError()

View file

@ -37,4 +37,4 @@ class Module(ModuleManager.BaseModule):
else:
event["stderr"].write("No results found")
else:
raise utils.EventsResultsError()
raise utils.EventResultsError()

View file

@ -86,4 +86,4 @@ class Module(ModuleManager.BaseModule):
else:
event["stderr"].write("No weather information for this location")
else:
raise utils.EventsResultsError()
raise utils.EventResultsError()

View file

@ -28,5 +28,5 @@ class Module(ModuleManager.BaseModule):
else:
event["stderr"].write("No results found")
else:
raise utils.EventsResultsError()
raise utils.EventResultsError()

View file

@ -30,4 +30,4 @@ class Module(ModuleManager.BaseModule):
else:
event["stdout"].write("No results")
else:
raise utils.EventsResultsError()
raise utils.EventResultsError()

View file

@ -165,7 +165,7 @@ class Module(ModuleManager.BaseModule):
else:
raise utils.EventError("No videos found")
else:
raise utils.EventsResultsError()
raise utils.EventResultsError()
if url:
out = self._from_url(url)
@ -175,7 +175,7 @@ class Module(ModuleManager.BaseModule):
out = "%s %s" % (out, short_url)
event["stdout"].write(out)
else:
raise utils.EventsResultsError()
raise utils.EventResultsError()
else:
event["stderr"].write("No search phrase provided")

View file

@ -5,6 +5,8 @@ from . import cli, consts, datetime, decorators, irc, http, parse, security
from .decorators import export, hook, kwarg
from .settings import (BoolSetting, FunctionSetting, IntRangeSetting,
IntSetting, OptionsSetting, sensitive_format, SensitiveSetting, Setting)
from .errors import (EventError, EventsNotEnoughArgsError, EventResultsError,
EventUsageError)
class Direction(enum.Enum):
Send = 0
@ -13,18 +15,6 @@ class Direction(enum.Enum):
def prevent_highlight(nickname: str) -> str:
return nickname[0]+"\u200c"+nickname[1:]
class EventError(Exception):
pass
class EventsResultsError(EventError):
def __init__(self):
EventError.__init__(self, "Failed to load results")
class EventsNotEnoughArgsError(EventError):
def __init__(self, n):
EventError.__init__(self, "Not enough arguments (minimum %d)" % n)
class EventsUsageError(EventError):
def __init__(self, usage):
EventError.__init__(self, "Not enough arguments, usage: %s" % usage)
class MultiCheck(object):
def __init__(self,
requests: typing.List[typing.Tuple[str, typing.List[str]]]):

12
src/utils/errors.py Normal file
View file

@ -0,0 +1,12 @@
class EventError(Exception):
pass
class EventResultsError(EventError):
def __init__(self):
EventError.__init__(self, "Failed to load results")
class EventNotEnoughArgsError(EventError):
def __init__(self, n):
EventError.__init__(self, "Not enough arguments (minimum %d)" % n)
class EventUsageError(EventError):
def __init__(self, usage):
EventError.__init__(self, "Not enough arguments, usage: %s" % usage)