From 74a06e0b79cbd298a9971a1d2cb66e5c4e3214dd Mon Sep 17 00:00:00 2001
From: Hornwitser <discord@hornwitser.no>
Date: Tue, 29 Sep 2015 09:19:33 +0200
Subject: [PATCH] Change behaviour of on_error

Change how the old style on_error event is called to match the new style
on_error event.  Both are now called in case an exception is raised in
an user defined event handler, and will by default print the arguments
of the event tha raised the exception and the traceback for the
exception.  In addition, overridding the on_error handler supresses this
behaviour.
---
 discord/client.py |  5 ++---
 docs/api.rst      | 34 ++++++++++++++++++++++------------
 2 files changed, 24 insertions(+), 15 deletions(-)

diff --git a/discord/client.py b/discord/client.py
index c59f38098..8b68ad807 100644
--- a/discord/client.py
+++ b/discord/client.py
@@ -360,7 +360,7 @@ class Client(object):
         self.events = {
             'on_ready': _null_event,
             'on_disconnect': _null_event,
-            'on_error': _null_event,
+            'on_error': self.on_error,
             'on_response': _null_event,
             'on_message': _null_event,
             'on_message_delete': _null_event,
@@ -457,8 +457,7 @@ class Client(object):
             log.info('attempting to invoke event {}'.format(event_name))
             self.events[event_name](*args, **kwargs)
         except Exception as e:
-            log.error('an error ({}) occurred in event {} so on_error is invoked instead'.format(type(e).__name__, event_name))
-            self.events['on_error'](event_name, *sys.exc_info())
+            self.events['on_error'](event_name, *args, **kwargs)
 
     def handle_socket_update(self, event, data):
         method = '_'.join(('handle', event.lower()))
diff --git a/docs/api.rst b/docs/api.rst
index ef3247fc0..2d4bd69b4 100644
--- a/docs/api.rst
+++ b/docs/api.rst
@@ -30,18 +30,28 @@ All events are 'sandboxed', in that if an exception is thrown while the event is
 
     Called when the client disconnects for whatever reason. Be it error or manually.
 
-.. function:: on_error(event, type, value, traceback)
-
-    Usually when an event throws an uncaught exception, it is swallowed. If you want to handle
-    the uncaught exceptions for whatever reason, this event is called. If an exception is thrown
-    on this event then it propagates (i.e. it is not swallowed silently).
-
-    The parameters for this event are retrieved through the use of ``sys.exc_info()``.
-
-    :param event: The event name that had the uncaught exception.
-    :param type: The type of exception that was swallowed.
-    :param value: The actual exception that was swallowed.
-    :param traceback: The traceback object representing the traceback of the exception swallowed.
+.. function:: on_error(event, \*args, \*\*kwargs)
+
+    Usually when an event throws an uncaught exception, a traceback is
+    printed to stderr and the exception is ignored.  If you want to
+    change this behaviour and handle the uncaught exception for whatever
+    reason, this event can be overridden.  The default behaviour for
+    on_error is printing a traceback and then ignoring the exception,
+    but defining an on_error handler will supress this behaviour.
+
+    If you want exception to propogate out of the :class:`Client` class
+    you can define an ``on_error`` handler consisting of a single empty
+    ``raise`` statement.  Exceptions raised by ``on_error`` will not be
+    handled in any way by :class:`Client`.
+
+    The information of the exception rasied can be retreived with a
+    standard call to ``sys.exc_info()``.
+
+    :param event: The name of the event that raised the exception.
+    :param args: The positional arguments for the event that raised the
+        exception.
+    :param kwargs: The keyword arguments for the event that raised the
+        execption.
 
 .. function:: on_message(message)