From 8ea6db9422301765ae350d5c271246bc5245b1bd Mon Sep 17 00:00:00 2001 From: jesopo Date: Sat, 20 Oct 2018 20:51:29 +0100 Subject: [PATCH] Standardise "Failed to load results" errors! --- modules/bitcoin.py | 2 +- modules/books.py | 2 +- modules/define.py | 4 ++-- modules/google.py | 4 ++-- modules/haveibeenpwned.py | 2 +- modules/imdb.py | 2 +- modules/ip_addresses.py | 2 +- modules/lastfm.py | 2 +- modules/soundcloud.py | 2 +- modules/spotify.py | 2 +- modules/thesaurus.py | 2 +- modules/trakt.py | 2 +- modules/upc.py | 2 +- modules/urbandictionary.py | 2 +- modules/weather.py | 2 +- modules/wikipedia.py | 2 +- modules/wolframalpha.py | 2 +- modules/youtube.py | 2 +- src/utils/__init__.py | 3 +++ 19 files changed, 23 insertions(+), 20 deletions(-) diff --git a/modules/bitcoin.py b/modules/bitcoin.py index 46c84596..29c2fcd7 100644 --- a/modules/bitcoin.py +++ b/modules/bitcoin.py @@ -22,4 +22,4 @@ class Module(ModuleManager.BaseModule): event["stderr"].write("Unknown currency, available " "currencies: %s" % ", ".join(page.keys())) else: - event["stderr"].write("Failed to load results") + raise utils.EventsResultsError() diff --git a/modules/books.py b/modules/books.py index 6555c156..d10cdd32 100644 --- a/modules/books.py +++ b/modules/books.py @@ -34,7 +34,7 @@ class Module(ModuleManager.BaseModule): else: event["stderr"].write("Unable to find book") else: - event["stderr"].write("Failed to load results") + raise utils.EventsResultsError() @utils.hook("received.command.isbn", min_args=1) def isbn(self, event): diff --git a/modules/define.py b/modules/define.py index b2714b12..b86687c0 100644 --- a/modules/define.py +++ b/modules/define.py @@ -39,7 +39,7 @@ class Module(ModuleManager.BaseModule): else: event["stderr"].write("No definitions found") else: - event["stderr"].write("Failed to load results") + raise utils.EventsResultsError() @utils.hook("received.command.randomword") def random_word(self, event): @@ -63,6 +63,6 @@ class Module(ModuleManager.BaseModule): event["stdout"].write("Random Word: %s - Definition: %s" % ( page["word"], definition["text"])) else: - event["stderr"].write("Failed to load results") + raise utils.EventsResultsError() else: event["stderr"].write("Try again in a couple of seconds") diff --git a/modules/google.py b/modules/google.py index 076ba752..5b8e2443 100644 --- a/modules/google.py +++ b/modules/google.py @@ -29,7 +29,7 @@ class Module(ModuleManager.BaseModule): else: event["stderr"].write("No results found") else: - event["stderr"].write("Failed to load results") + raise utils.EventsResultsError() else: event["stderr"].write("No phrase provided") @@ -56,6 +56,6 @@ class Module(ModuleManager.BaseModule): else: event["stderr"].write("No suggestions found") else: - event["stderr"].write("Failed to load results") + raise utils.EventsResultsError() else: event["stderr"].write("No phrase provided") diff --git a/modules/haveibeenpwned.py b/modules/haveibeenpwned.py index 3812dd58..326adf03 100644 --- a/modules/haveibeenpwned.py +++ b/modules/haveibeenpwned.py @@ -23,4 +23,4 @@ class Module(ModuleManager.BaseModule): event["stdout"].write("It seems '%s' has not been pwned" % ( event["args"])) else: - event["stderr"].write("Failed to load results") + raise utils.EventsResultsError() diff --git a/modules/imdb.py b/modules/imdb.py index 667a26f2..b396b5ba 100644 --- a/modules/imdb.py +++ b/modules/imdb.py @@ -28,4 +28,4 @@ class Module(ModuleManager.BaseModule): else: event["stderr"].write("Title not found") else: - event["stderr"].write("Failed to load results") + raise utils.EventsResultsError() diff --git a/modules/ip_addresses.py b/modules/ip_addresses.py index 2877e000..6441f4b7 100644 --- a/modules/ip_addresses.py +++ b/modules/ip_addresses.py @@ -52,7 +52,7 @@ class Module(ModuleManager.BaseModule): else: event["stderr"].write("No geoip data found") else: - event["stderr"].write("Failed to load results") + raise utils.EventsResultsError() @utils.hook("received.command.rdns") def rdns(self, event): diff --git a/modules/lastfm.py b/modules/lastfm.py index e67c6af1..73153a39 100644 --- a/modules/lastfm.py +++ b/modules/lastfm.py @@ -84,4 +84,4 @@ class Module(ModuleManager.BaseModule): "The user '%s' has never scrobbled before" % ( shown_username)) else: - event["stderr"].write("Failed to load results") + raise utils.EventsResultsError() diff --git a/modules/soundcloud.py b/modules/soundcloud.py index 20285222..76324536 100644 --- a/modules/soundcloud.py +++ b/modules/soundcloud.py @@ -59,4 +59,4 @@ class Module(ModuleManager.BaseModule): event["stdout"].write("%s [%s] (posted by %s) %s" % (title, duration, user, link)) else: - event["stderr"].write("Failed to load results") + raise utils.EventsResultsError() diff --git a/modules/spotify.py b/modules/spotify.py index b26a66de..0bd92de6 100644 --- a/modules/spotify.py +++ b/modules/spotify.py @@ -24,4 +24,4 @@ class Module(ModuleManager.BaseModule): else: event["stderr"].write("No results found") else: - event["stderr"].write("Failed to load results") + raise utils.EventsResultsError() diff --git a/modules/thesaurus.py b/modules/thesaurus.py index 9452ab26..619df439 100644 --- a/modules/thesaurus.py +++ b/modules/thesaurus.py @@ -41,4 +41,4 @@ class Module(ModuleManager.BaseModule): else: event["stderr"].write("Category not found") else: - event["stderr"].write("Failed to load results") + raise utils.EventsResultsError() diff --git a/modules/trakt.py b/modules/trakt.py index 8adc3cc4..12b9c25d 100644 --- a/modules/trakt.py +++ b/modules/trakt.py @@ -54,4 +54,4 @@ class Module(ModuleManager.BaseModule): event["stderr"].write( "%s is not watching anything" % username) else: - event["stderr"].write("Failed to load results") + raise utils.EventsResultsError() diff --git a/modules/upc.py b/modules/upc.py index f67f06b9..ed265f6e 100644 --- a/modules/upc.py +++ b/modules/upc.py @@ -47,4 +47,4 @@ class Module(ModuleManager.BaseModule): ", size: %s, price: %s)" % ( brand, title, description, weight, size, pricing)) else: - event["stderr"].write("Failed to load results") + raise utils.EventsResultsError() diff --git a/modules/urbandictionary.py b/modules/urbandictionary.py index 314b492f..b63683c2 100644 --- a/modules/urbandictionary.py +++ b/modules/urbandictionary.py @@ -32,4 +32,4 @@ class Module(ModuleManager.BaseModule): else: event["stderr"].write("No results found") else: - event["stderr"].write("Failed to load results") + raise utils.EventsResultsError() diff --git a/modules/weather.py b/modules/weather.py index 78fe0b7f..b5d79a8a 100644 --- a/modules/weather.py +++ b/modules/weather.py @@ -33,4 +33,4 @@ class Module(ModuleManager.BaseModule): else: event["stderr"].write("No weather information for this location") else: - event["stderr"].write("Failed to load results") + raise utils.EventsResultsError() diff --git a/modules/wikipedia.py b/modules/wikipedia.py index 08b3210e..63def32d 100644 --- a/modules/wikipedia.py +++ b/modules/wikipedia.py @@ -25,5 +25,5 @@ class Module(ModuleManager.BaseModule): else: event["stderr"].write("No results found") else: - event["stderr"].write("Failed to load results") + raise utils.EventsResultsError() diff --git a/modules/wolframalpha.py b/modules/wolframalpha.py index 7e25098a..050b917d 100644 --- a/modules/wolframalpha.py +++ b/modules/wolframalpha.py @@ -25,4 +25,4 @@ class Module(ModuleManager.BaseModule): else: event["stdout"].write("No results") else: - event["stderr"].write("Failed to load results") + raise utils.EventsResultsError() diff --git a/modules/youtube.py b/modules/youtube.py index 4beb3bb7..0477a1d5 100644 --- a/modules/youtube.py +++ b/modules/youtube.py @@ -99,7 +99,7 @@ class Module(ModuleManager.BaseModule): else: event["stderr"].write("No videos found") else: - event["stderr"].write("Failed to load results") + raise utils.EventsResultsError() if video_id: event["stdout"].write(self.video_details(video_id)) else: diff --git a/src/utils/__init__.py b/src/utils/__init__.py index a95790da..658a434d 100644 --- a/src/utils/__init__.py +++ b/src/utils/__init__.py @@ -136,6 +136,9 @@ def prevent_highlight(nickname): class EventError(Exception): pass +class EventsResultsError(EventError): + def __init__(self): + EventError.__init__(self, "Failed to load results") def _set_get_append(obj, setting, item): if not hasattr(obj, setting):