ArgumentParser which throws an exception instead of print errors.
authorCMDR furrycat <elite@furrycat.net>
Thu, 10 Nov 2016 08:27:21 +0000 (08:27 +0000)
committerCMDR furrycat <elite@furrycat.net>
Thu, 10 Nov 2016 14:21:34 +0000 (14:21 +0000)
bot.py
throwingargparse.py [new file with mode: 0644]

diff --git a/bot.py b/bot.py
index 7544d83..835bed4 100644 (file)
--- 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 (file)
index 0000000..8ef63c5
--- /dev/null
@@ -0,0 +1,8 @@
+import argparse
+
+class ArgumentParserError(Exception):
+  pass
+
+class ThrowingArgumentParser(argparse.ArgumentParser):
+  def error(self, message):
+    raise ArgumentParserError(message)