From: CMDR furrycat Date: Thu, 10 Nov 2016 08:27:21 +0000 (+0000) Subject: ArgumentParser which throws an exception instead of print errors. X-Git-Url: http://git.furryclan.net/?a=commitdiff_plain;h=eed2fa24c6bfed950b7efefc0ef9249b95a40e05;p=furrycat%2Fcatbot.git ArgumentParser which throws an exception instead of print errors. --- diff --git a/bot.py b/bot.py index 7544d83..835bed4 100644 --- a/bot.py +++ b/bot.py @@ -463,3 +463,8 @@ def iso8601(timestamp): def digest(text): return hashlib.sha224(text.encode('utf-8')).hexdigest() + +@asyncio.coroutine +def say_exception(destination, exception): + result = yield from say_many(destination, ['```py', str(exception), '```']) + return result diff --git a/throwingargparse.py b/throwingargparse.py new file mode 100644 index 0000000..8ef63c5 --- /dev/null +++ b/throwingargparse.py @@ -0,0 +1,8 @@ +import argparse + +class ArgumentParserError(Exception): + pass + +class ThrowingArgumentParser(argparse.ArgumentParser): + def error(self, message): + raise ArgumentParserError(message)