def send_error(): """ Sends an error response with the contents of the exception that was raised. """ exc_type, exc_value, dummy_exc_trace = sys.exc_info() formated_tb = traceback.format_exc() try: self.sendData( ( RPC_ERROR, request_id, exc_type.__name__, exc_value._args, exc_value._kwargs, formated_tb, ) ) except AttributeError: # This is not a deluge exception (object has no attribute '_args), let's wrap it log.warning( 'An exception occurred while sending RPC_ERROR to ' 'client. Wrapping it and resending. Error to ' 'send(causing exception goes next):\n%s', formated_tb, ) try: raise WrappedException( str(exc_value), exc_type.__name__, formated_tb ) except WrappedException: send_error() except Exception as ex: log.error( 'An exception occurred while sending RPC_ERROR to client: %s', ex )
def sendError(): """ Sends an error response with the contents of the exception that was raised. """ exceptionType, exceptionValue, exceptionTraceback = sys.exc_info() formated_tb = "".join(traceback.format_tb(exceptionTraceback)) try: self.sendData(( RPC_ERROR, request_id, exceptionType.__name__, exceptionValue._args, exceptionValue._kwargs, formated_tb )) except Exception, err: # This most likely not a deluge exception, let's wrap it log.error("An exception occurred while sending RPC_ERROR to " "client. Wrapping it and resending. Error to " "send(causing exception goes next):\n%s", formated_tb) log.exception(err) try: raise WrappedException(str(exceptionValue), exceptionType.__name__, formated_tb) except: sendError()