def _ebDeferSetUp(self, failure, result): if failure.check(SkipTest): result.addSkip(self, self._getReason(failure)) else: result.addError(self, failure) result.upDownError("setUp", failure, warn=False, printStatus=False) if failure.check(KeyboardInterrupt): result.stop()
def _ebDeferSetUp(self, failure, result): if failure.check(SkipTest): result.addSkip(self, self._getSkipReason(self.setUp, failure.value)) else: result.addError(self, failure) if failure.check(KeyboardInterrupt): result.stop() return self.deferRunCleanups(None, result)
def eb(failure): if failure.check(errors.NoMethodError): common.errorRaise("No method '%s' on component '%s'." % ( methodName, p.componentId)) elif failure.check(errors.SleepingComponentError): common.errorRaise( "Component '%s' is sleeping." % p.componentId) else: common.errorRaise(log.getFailureMessage(failure))
def eb(failure): # FIXME if failure.check(errors.NoMethodError) \ or failure.check(flavors.NoSuchMethod): common.errorRaise("No method '%s' on manager." % methodName) elif failure.check(errors.RemoteRunError): common.errorRaise(log.getFailureMessage(failure)) else: common.errorRaise(log.getFailureMessage(failure))
def eb(failure): # FIXME if failure.check(errors.NoMethodError): common.errorRaise("No method '%s' on worker '%s'." % (methodName, workerName)) elif failure.check(errors.SleepingComponentError): common.errorRaise("Component '%s' is sleeping." % p.componentId) elif failure.check(errors.RemoteRunError): common.errorRaise(log.getFailureMessage(failure)) else: common.errorRaise(log.getFailureMessage(failure))
def _error_handler(self, failure): if failure.check(tw_error.ConnectionRefusedError): self._on_disconnected() self.reconnect() raise NotConnectedError("Database connection refused.") elif (failure.check(httpclient.RequestError) and failure.value.cause and isinstance(failure.value.cause, tw_error.ConnectionDone)): self._on_disconnected() self.reconnect() raise NotConnectedError("Connection to the database was lost.") else: failure.raiseException()
def _sendErrorAnswer(self, failure, qid): del self._theirQuestions[qid] if failure.check(KnownError): body = failure.value[0] self._sendQANFrame(KnownErrorAnswer(body, qid)) elif failure.check(defer.CancelledError): self._sendQANFrame(UnknownErrorAnswer("CancelledError", qid)) else: self._logError("Peer's Question #%d caused uncaught " "exception" % (qid,), failure) # We intentionally do not reveal information about the # exception. self._sendQANFrame(UnknownErrorAnswer("Uncaught exception", qid))
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 eb(failure): if failure.check(errors.ComponentMoodError, errors.BusyComponentError): common.errorRaise("Component '%s' is in the wrong mood." % self.parentCommand.componentId) else: common.errorRaise(log.getFailureMessage(failure))
def expected(self, failure): if self.errors is None: return True for error in self.errors: if failure.check(error): return True return False
def _cbDeferRunCleanups(self, cleanupResults, result): for flag, failure in cleanupResults: if flag == defer.FAILURE: result.addError(self, failure) if failure.check(KeyboardInterrupt): result.stop() self._passed = False
def errback(failure): try: if failure.check(ServerMessage): self.root.runCallback('msg', failure.getErrorMessage()) self.root._failure() finally: self._startCall()
def _process(self, failure, data_cache, exceptions): for (exc, key, max_count, init_backoff, incr_backoff, max_backoff) in exceptions: if failure.check(*exc) is not None: count = data_cache.get(key, 0) + 1 if max_count is not None and count >= max_count: zc.async.utils.tracelog.warning( 'Retry policy for job %r is not retrying after %d ' 'counts of %s occurrences', self.parent, count, key) return False elif count==1 or not count % self.log_every: zc.async.utils.tracelog.warning( 'Retry policy for job %r requests another attempt ' 'after %d counts of %s occurrences', self.parent, count, key, exc_info=True) backoff = min(max_backoff, (init_backoff + (count-1) * incr_backoff)) if backoff: time.sleep(backoff) data_cache[key] = count data_cache['last_' + key] = failure if 'first_active' not in data_cache: data_cache['first_active'] = self.parent.active_start return True return False
def _defaultErrback(self, failure, request): if failure.check(errors.UnknownComponentError, errors.NotAuthenticatedError) is None: # If something else went wrong, we want to disconnect the client # and give them a 500 Internal Server Error. self._handleUnauthorized(request, http.INTERNAL_SERVER_ERROR) return failure
def _eb(failure): if failure.check(*expectedFailures): return failure.value else: output = ('\nExpected: %r\nGot:\n%s' % (expectedFailures, str(failure))) raise self.failureException(output)
def testVERIFYBadKeyFailed(failure, msg, node, nKu, host, port): if failure.check('flud.protocol.FludCommUtil.NotFoundException'): print "%s" % msg return testDELETEBadKey(nKu, node, host, port) else: print "\nVERIFYBadKey expected NotFoundException," \ " but got a different failure:" raise failure
def testSTORESmallFailed(failure, msg, node, nKu, host, port): if failure.check('flud.protocol.FludCommUtil.BadCASKeyException'): print "%s" % msg return testSTOREBadKeyLarge(nKu, node, host, port) else: print "\nSTORESmall expected BadCASKeyException," \ " but got a different failure:" raise failure
def testRETRIEVENotFoundFailed(failure, msg, node, nKu, host, port): if failure.check('flud.protocol.FludCommUtil.NotFoundException'): print "%s" % msg return testRETRIEVEIllegalPath(nKu, node, host, port) else: print "\nRETRIEVENotFound expected NotFoundException," \ " but got a different failure:" raise failure
def matchException(failure): for errorState, backOff in self.backOffs.iteritems(): if 'errorTypes' not in backOff: continue if failure.check(*backOff['errorTypes']): return errorState return 'other'
def testVERIFYBadLengthFailed(failure, msg, node, nKu, host, port): if failure.check('flud.protocol.FludCommUtil.BadRequestException'): print "%s" % msg return testVERIFYBadKey(nKu, node, host, port) else: print "\nVERIFYBadLength expected BadRequestException," \ " but got a different failure:" raise failure
def errback(failure): if not self.currentlyAsking: return self.currentlyAsking = False if failure.check(ServerMessage): self.root.runCallback('msg', failure.getErrorMessage()) self.root._failure() self._startCall()
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 errback(failure, exp_error=None, exp_class=None, result=None, exception=None): if exp_class: self.assertTrue(failure.check(exp_class) is not None) if exp_error: self.assertEqual(exp_error, failure.value) if exception: raise exception return result or failure
def expected(self, failure): """ @param failure: A L{twisted.python.failure.Failure}. @return: C{True} if C{failure} is expected, C{False} otherwise. """ if self.errors is None: return True for error in self.errors: if failure.check(error): return True return False
def _defaultErrback(self, failure, request): if failure.check(errors.NotAuthenticatedError) is None: # If something else went wrong, we want to either disconnect the # client and give them a 500 Internal Server Error or just allow # them, depending on the configuration. self.debug("Authorization request failed: %s", log.getFailureMessage(failure)) if self._allowDefault: self.debug("Authorization failed, but allowing anyway") return None self._handleUnauthorized(request, http.INTERNAL_SERVER_ERROR) return failure
def processing_failed(failure, error_handlers): # The failure processor writes to the request. If the # request is already finished we should suppress failure # processing. We don't return failure here because there # is no way to surface this failure to the user if the # request is finished. if request_finished[0]: if not failure.check(defer.CancelledError): log.err(failure, "Unhandled Error Processing Request.") return # If there are no more registered handlers, apply some defaults if len(error_handlers) == 0: if failure.check(HTTPException): he = failure.value request.setResponseCode(he.code) resp = he.get_response({}) for header, value in resp.headers: request.setHeader(ensure_utf8_bytes(header), ensure_utf8_bytes(value)) return ensure_utf8_bytes(he.get_body({})) else: request.processingFailed(failure) return error_handler = error_handlers[0] # Each error handler is a tuple of (list_of_exception_types, handler_fn) if failure.check(*error_handler[0]): d = defer.maybeDeferred(self._app.execute_error_handler, error_handler[1], request, failure) return d.addErrback(processing_failed, error_handlers[1:]) return processing_failed(failure, error_handlers[1:])
def handle_unhandled(failure): # If there are no more registered handlers, apply some defaults if failure.check(HTTPException): he = failure.value request.setResponseCode(he.code) resp = he.get_response({}) for header, value in resp.headers: request.setHeader(ensure_utf8_bytes(header), ensure_utf8_bytes(value)) return ensure_utf8_bytes(he.get_body({})) else: request.processingFailed(failure) return
def handle_various_errors(failure, vin_or_report, _id): # Do I actually need vin_or_report? if failure.check(NoBalanceError): balance_ok = False print "No balance remaining: no more VINs will be run." error_items['not_attempted'].append(_id) elif failure.check(InvalidVINError): print _id + " is an invalid " + vin_or_report error_items['invalid_vin'].append(_id) elif failure.check(FailNMVTISError): print _id + " was not run, NMVTIS was not available." error_items['fail_nmvtis'].append(_id) elif failure.check(NoRecordsError): print _id + " did not exist in the NMVTIS database." error_items['no_record'].append(_id) else: failure.raiseException()
def _handle_failure(self, failure): if self._finished: if failure.check(CancelledError): return None # we cancel pending tasks on finish. else: # Cannot really do anything with this failure # since we've already called back to the user. return failure else: # Lets remember the failure and iterate. This # will cause the traversal to finish and # all other pending operations to be cancelled. self._caught_failure = failure self._iterate() return None
def _response_eb(self, failure, first, last, retries): """Error back for HTTP errors""" if not self._paused: # if it's not last retry and failure wasn't our fault we retry if (retries < FLAGS.get_entries_max_retries and not failure.check(HTTPClientError)): logging.info("Retrying get-entries for range <%d, %d> retry: %d" % (first, last, retries)) d = task.deferLater(self._reactor, self._calculate_retry_delay(retries), self._fetch_parsed_entries, first, last) d.addErrback(self._response_eb, first, last, retries + 1) return d else: self.__fail(failure)
def _ebLookup(self, failure, sport, cport): if failure.check(IdentError): self.sendLine('%d, %d : ERROR : %s' % (sport, cport, failure.value)) else: log.err(failure) self.sendLine('%d, %d : ERROR : %s' % (sport, cport, IdentError(failure.value)))
def _ebDeferTearDown(self, failure, result): result.addError(self, failure) if failure.check(KeyboardInterrupt): result.stop() result.upDownError('tearDown', failure, warn=False, printStatus=True) self._passed = False
def _eb(failure): if failure.check(*expectedFailures): return failure.value else: raise self.failureException("%r not expected (%r)" % (failure, expectedFailures))
def _ebDeferTearDown(self, failure, result): result.addError(self, failure) if failure.check(KeyboardInterrupt): result.stop() self._passed = False