def _ebRender(self, failure, functionPath, args, request): logger.error("Error during render " + functionPath + ": " + failure.getTraceback()) # Prepare a Fault result to return result = {} result['faultString'] = functionPath + " " + str(args) result['faultCode'] = str(failure.type) + ": " + str(failure.value) + " " result['faultTraceback'] = failure.getTraceback() return result
def _ebRender(self, failure, functionPath, args, request): logger.error("Error during render " + functionPath + ": " + failure.getTraceback()) # Prepare a Fault result to return result = {} result['faultString'] = functionPath + " " + str(args) result['faultCode'] = str(failure.type) + ": " + str( failure.value) + " " result['faultTraceback'] = failure.getTraceback() return result
def __init__(self, failure): traceback = html.Element("pre") traceback.text = failure.getTraceback() super(StartFailedPage, self).__init__(status=int(SERVICE_UNAVAILABLE), brief="MAAS failed to start", detail=html.tostring(traceback, encoding=str))
def unexpectedError(self, failure, request=None): # If the sub-process exited abnormally, the stderr it produced is # probably a much more interesting traceback than the one attached to # the Failure we've been passed. traceback = None if failure.check(error.ProcessTerminated): traceback = getattr(failure, "error", None) if traceback is None: traceback = failure.getTraceback() errorlog.globalErrorUtility.raising((failure.type, failure.value, traceback), request)
def unexpectedError(self, failure, request=None): # If the sub-process exited abnormally, the stderr it produced is # probably a much more interesting traceback than the one attached to # the Failure we've been passed. traceback = None if failure.check(error.ProcessTerminated): traceback = getattr(failure, 'error', None) if traceback is None: traceback = failure.getTraceback() errorlog.globalErrorUtility.raising( (failure.type, failure.value, traceback), request)
def on_failure(self, failure, request): """ Handle exceptions raised during RestResource processing :param failure: ``twisted.python.failure.Failure`` instance :param request: ``twisted.web.server.Request`` instance """ fq_name = self.__module__ + '.' + self.__class__.__name__ file_path = abspath(inspect.getfile(self.__class__)) if failure.check(CancelledError): # the request / deferred chain has been cancelled early. # doesn't matter if we respond no one is listening. rstr = err = 'Request was cancelled' elif failure.check(_DefGen_Return): failure.printBriefTraceback() err = dedent(''' Received a Deferred Generator Response from Resource (%s) in the method: [%s] .................................... This indicates you may be missing a yield statement and the decorator `@defer.inlineCallbacks`. File: %s If you do not have a yield statement, you should use a regular `return` statement and remove `defer.returnValue()` ''' % (fq_name, request.method_called, file_path)).strip() log.err(err + ' - ' + failure.getErrorMessage()) rstr = self.ERROR_CLASS( INTERNAL_SERVER_ERROR, err, failure.getErrorMessage(), is_logged=False ).render(request) else: log.err('Exception in Resource (%s) [%s] <%s> - %s' % ( fq_name, request.method_called, file_path, failure.getErrorMessage())) failure.printTraceback() rstr = self.ERROR_CLASS( INTERNAL_SERVER_ERROR, 'Unhandled Error', 'Exception in Resource (%s) [%s] <%s> - %s' % ( fq_name, request.method_called, file_path, failure.getTraceback()), is_logged=False ).render(request) if request.finished: return request.write(rstr) request.finish()
def unexpectedError(self, failure): request = errorlog.ScriptRequest([('branch_id', self.branch_id), ('source', self.source_url), ('dest', self.destination_url), ('error-explanation', failure.getErrorMessage())]) request.URL = get_canonical_url_for_branch_name(self.unique_name) # If the sub-process exited abnormally, the stderr it produced is # probably a much more interesting traceback than the one attached to # the Failure we've been passed. tb = None if failure.check(error.ProcessTerminated, UnexpectedStderr): tb = getattr(failure, 'error', None) if tb is None: tb = failure.getTraceback() errorlog.globalErrorUtility.raising((failure.type, failure.value, tb), request) self.logger.info('Recorded %s', request.oopsid)
def unexpectedError(self, failure): request = errorlog.ScriptRequest([ ('branch_id', self.branch_id), ('source', self.source_url), ('dest', self.destination_url), ('error-explanation', failure.getErrorMessage())]) request.URL = get_canonical_url_for_branch_name(self.unique_name) # If the sub-process exited abnormally, the stderr it produced is # probably a much more interesting traceback than the one attached to # the Failure we've been passed. tb = None if failure.check(error.ProcessTerminated, UnexpectedStderr): tb = getattr(failure, 'error', None) if tb is None: tb = failure.getTraceback() errorlog.globalErrorUtility.raising( (failure.type, failure.value, tb), request) self.logger.info('Recorded %s', request.oopsid)
def _format_error(failure): """ Logs the failure backtrace, and returns a json containing the error message. If a exception declares the 'expected' attribute as True, we will not print a full traceback. instead, we will dispatch the ``exception`` message attribute as the ``error`` field in the response json. """ expected = getattr(failure.value, 'expected', False) if not expected: log.error('[DISPATCHER] Unexpected error!') log.error('{0!r}'.format(failure.value)) log.error(failure.getTraceback()) # if needed, we could add here the exception type as an extra field return json.dumps({'error': failure.value.message, 'result': None})
def parseEb(failure): self.debug("parse: eb: failure: %r\n%s\n", failure.getErrorMessage(), failure.getTraceback()) # we can get here even before we run the reactor below; # so schedule a stop instead of doing it here # self.reactor.stop() self.reactor.callLater(0, self.reactor.stop) if failure.check(command.CommandExited): self.stderr.write(failure.value.output + "\n") reason = failure.value.status self.returnValue = reason return reason self.warning("errback: %r", failure.getErrorMessage()) self.stderr.write("Failure: %s\n" % failure.value) self.returnValue = failure # we handled it by storing it for reraising, so don't # return it return
def parseEb(failure): self.debug('parse: eb: failure: %r\n%s\n', failure.getErrorMessage(), failure.getTraceback()) # we can get here even before we run the reactor below; # so schedule a stop instead of doing it here # self.reactor.stop() self.reactor.callLater(0, self.reactor.stop) if failure.check(command.CommandExited): self.stderr.write(failure.value.output + '\n') reason = failure.value.status self.returnValue = reason return reason self.warning('errback: %r', failure.getErrorMessage()) self.stderr.write('Failure: %s\n' % failure.value) self.returnValue = failure # we handled it by storing it for reraising, so don't # return it return
def report_error(failure, line_fun=None, include_stacktrace=False): if getattr(failure, "handled", False): return failure failure.handled = True if line_fun is None: def line_fun(line): logger.debug(line) if isinstance(failure, SshFailure): return failure if hasattr(failure.value, 'component'): line_fun('%s%s: %s' % (_determine_issued_command(failure), failure.value.component, failure.getErrorMessage())) else: line_fun(failure.getErrorMessage()) logger.debug(failure.getTraceback()) if include_stacktrace: for line in failure.getBriefTraceback().splitlines(): line_fun(line) return failure
def _catch_all(self, failure): self.logger.error(failure.getTraceback()) self.reply('error')
def fail(failure): logger.error("Error while receiving message: %s" % failure.getTraceback())
def unhandled(failure): logger.error(failure.getTraceback())