"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) acronyms.append(element.expan.string)
event["stdout"].write("%s: %s" % (query, ", ".join(acronyms))) event["stdout"].write("%s: %s" % (query, ", ".join(acronyms)))
else: else:
raise utils.EventsResultsError() raise utils.EventResultsError()

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -96,4 +96,4 @@ class Module(ModuleManager.BaseModule):
"The user '%s' has never scrobbled before" % ( "The user '%s' has never scrobbled before" % (
shown_username)) shown_username))
else: 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) URL_ONIONOO_DETAILS, get_params={"search": search}, json=True)
if page and "relays" in page.data: if page and "relays" in page.data:
return page.data["relays"] return page.data["relays"]
raise utils.EventsResultsError() raise utils.EventResultsError()
def _format_relay_summary_message(relays, search): def _format_relay_summary_message(relays, search):
if len(relays) > 1: if len(relays) > 1:

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -165,7 +165,7 @@ class Module(ModuleManager.BaseModule):
else: else:
raise utils.EventError("No videos found") raise utils.EventError("No videos found")
else: else:
raise utils.EventsResultsError() raise utils.EventResultsError()
if url: if url:
out = self._from_url(url) out = self._from_url(url)
@ -175,7 +175,7 @@ class Module(ModuleManager.BaseModule):
out = "%s %s" % (out, short_url) out = "%s %s" % (out, short_url)
event["stdout"].write(out) event["stdout"].write(out)
else: else:
raise utils.EventsResultsError() raise utils.EventResultsError()
else: else:
event["stderr"].write("No search phrase provided") 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 .decorators import export, hook, kwarg
from .settings import (BoolSetting, FunctionSetting, IntRangeSetting, from .settings import (BoolSetting, FunctionSetting, IntRangeSetting,
IntSetting, OptionsSetting, sensitive_format, SensitiveSetting, Setting) IntSetting, OptionsSetting, sensitive_format, SensitiveSetting, Setting)
from .errors import (EventError, EventsNotEnoughArgsError, EventResultsError,
EventUsageError)
class Direction(enum.Enum): class Direction(enum.Enum):
Send = 0 Send = 0
@ -13,18 +15,6 @@ class Direction(enum.Enum):
def prevent_highlight(nickname: str) -> str: def prevent_highlight(nickname: str) -> str:
return nickname[0]+"\u200c"+nickname[1:] 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): class MultiCheck(object):
def __init__(self, def __init__(self,
requests: typing.List[typing.Tuple[str, typing.List[str]]]): 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)