def _process_error(self, reason):
        """
		Called when there is an error processing the request.
		
		*reason* (``twisted.internet.failure.Failure``) is the reason for
		failure.
		"""
        try:
            if not isinstance(reason, failure.Failure):
                # LIES! This is not an error.
                return

            # Log errors.
            log.err(reason, str(self))

            if self._disconnected or self.finished:
                # Since we are disconnected, return and do nothing.
                return

            if self._resp_error_cb:
                # Call error callback.
                try:
                    self._resp_error_cb(self, reason, self._resp_started,
                                        *self._resp_error_args,
                                        **self._resp_error_kw)
                except Exception as e:
                    log.err(e, str(self))

            if not self._resp_started:
                # Display Internal Server Error.
                code = http.INTERNAL_SERVER_ERROR
                if self.site.displayTracebacks:
                    body = _server_traceback_html.format(
                        path=urllib.escape(self.uri),
                        traceback=webutil.formatFailure(reason))
                else:
                    body = _server_error_html.format(
                        path=urllib.escape(self.uri))
                self.setResponseCode(code)
                self.setResponseEncoding(self._resp_enc or 'UTF-8')
                self.write(body)

            elif 'text/html' in self.responseHeaders.getRawHeaders(
                    'content-type', ('', ))[0]:
                # Since an error occured but we've already started writing the
                # response, do what we can.
                if self.site.displayTracebacks:
                    body = _server_traceback_html.format(
                        path=urllib.escape(self.uri),
                        traceback=webutil.formatFailure(reason))
                else:
                    body = "<h1>...Internal Server Error!</h1>"
                self.write(body)

        except Exception as e:
            log.err(e, str(self))

        finally:
            self.finish()
	def _process_error(self, reason):
		"""
		Called when there is an error processing the request.
		
		*reason* (``twisted.internet.failure.Failure``) is the reason for
		failure.
		"""
		try:
			if not isinstance(reason, failure.Failure):
				# LIES! This is not an error.
				return
		
			# Log errors.
			log.err(reason, str(self))
		
			if self._disconnected or self.finished:
				# Since we are disconnected, return and do nothing.
				return
			
			if self._resp_error_cb:
				# Call error callback.
				try:
					self._resp_error_cb(self, reason, self._resp_started, *self._resp_error_args, **self._resp_error_kw)
				except Exception as e:
					log.err(e, str(self))
		
			if not self._resp_started:
				# Display Internal Server Error.
				code = http.INTERNAL_SERVER_ERROR
				if self.site.displayTracebacks:
					body = _server_traceback_html.format(path=urllib.escape(self.uri), traceback=webutil.formatFailure(reason))
				else:
					body = _server_error_html.format(path=urllib.escape(self.uri))
				self.setResponseCode(code)
				self.setResponseEncoding(self._resp_enc or 'UTF-8')
				self.write(body)
			
			elif 'text/html' in self.responseHeaders.getRawHeaders('content-type', ('',))[0]:
				# Since an error occured but we've already started writing the
				# response, do what we can.
				if self.site.displayTracebacks:
					body = _server_traceback_html.format(path=urllib.escape(self.uri), traceback=webutil.formatFailure(reason))
				else:
					body = "<h1>...Internal Server Error!</h1>"
				self.write(body)
				
		except Exception as e:
			log.err(e, str(self))
			
		finally:
			self.finish()
Exemplo n.º 3
0
    def failed(self, why):
        # This can either be a BuildStepFailed exception/failure, meaning we
        # should call self.finished, or it can be a real exception, which should
        # be recorded as such.
        if why.check(BuildStepFailed):
            self.finished(FAILURE)
            return

        log.err(why, "BuildStep.failed; traceback follows")
        try:
            if self.progress:
                self.progress.finish()
            self.addHTMLLog("err.html", formatFailure(why))
            self.addCompleteLog("err.text", why.getTraceback())
            # could use why.getDetailedTraceback() for more information
            self.step_status.setText([self.name, "exception"])
            self.step_status.setText2([self.name])
            self.step_status.stepFinished(EXCEPTION)

            hidden = self._maybeEvaluate(self.hideStepIf, EXCEPTION, self)
            self.step_status.setHidden(hidden)
        except:
            log.msg("exception during failure processing")
            log.err()
            # the progress stuff may still be whacked (the StepStatus may
            # think that it is still running), but the build overall will now
            # finish
        try:
            self.releaseLocks()
        except:
            log.msg("exception while releasing locks")
            log.err()

        log.msg("BuildStep.failed now firing callback")
        self.deferred.callback(EXCEPTION)
Exemplo n.º 4
0
 def addLogWithFailure(self, why, logprefix=""):
     # helper for showing exceptions to the users
     try:
         yield self.addCompleteLog(logprefix + "err.text", why.getTraceback())
         yield self.addHTMLLog(logprefix + "err.html", formatFailure(why))
     except Exception:
         log.err(Failure(), "error while formatting exceptions")
Exemplo n.º 5
0
 def addLogWithFailure(self, why, logprefix=""):
     # helper for showing exceptions to the users
     try:
         yield self.addCompleteLog(logprefix + "err.text", why.getTraceback())
         yield self.addHTMLLog(logprefix + "err.html", formatFailure(why))
     except Exception:
         log.err(Failure(), "error while formatting exceptions")
Exemplo n.º 6
0
    def failed(self, why):
        # This can either be a BuildStepFailed exception/failure, meaning we
        # should call self.finish, or it can be a real exception, which should
        # be recorded as such.
        if why.check(BuildStepFailed):
            self.finished(FAILURE)
            return

        log.err(why, "BuildStep.failed; traceback follows")
        try:
            if self.progress:
                self.progress.finish()
            self.addHTMLLog("err.html", formatFailure(why))
            self.addCompleteLog("err.text", why.getTraceback())
            # could use why.getDetailedTraceback() for more information
            self.step_status.setText([self.name, "exception"])
            self.step_status.setText2([self.name])
            self.step_status.stepFinished(EXCEPTION)
        except:
            log.msg("exception during failure processing")
            log.err()
            # the progress stuff may still be whacked (the StepStatus may
            # think that it is still running), but the build overall will now
            # finish
        try:
            self.releaseLocks()
        except:
            log.msg("exception while releasing locks")
            log.err()

        log.msg("BuildStep.failed now firing callback")
        self.deferred.callback(EXCEPTION)
Exemplo n.º 7
0
    def failed(self, why):
        # if isinstance(why, pb.CopiedFailure): # a remote exception might
        # only have short traceback, so formatFailure is not as useful as
        # you'd like (no .frames, so no traceback is displayed)
        log.msg("BuildStep.failed, traceback follows")
        log.err(why)
        try:
            if self.progress:
                self.progress.finish()
            self.addHTMLLog("err.html", formatFailure(why))
            self.addCompleteLog("err.text", why.getTraceback())
            # could use why.getDetailedTraceback() for more information
            self.step_status.setText([self.name, "exception"])
            self.step_status.setText2([self.name])
            self.step_status.stepFinished(EXCEPTION)
        except:
            log.msg("exception during failure processing")
            log.err()
            # the progress stuff may still be whacked (the StepStatus may
            # think that it is still running), but the build overall will now
            # finish
        try:
            self.releaseLocks()
        except:
            log.msg("exception while releasing locks")
            log.err()

        log.msg("BuildStep.failed now firing callback")
        self.deferred.callback(EXCEPTION)
Exemplo n.º 8
0
    def processingFailed(self, reason):
        """
        Finish this request with an indication that processing failed and
        possibly display a traceback.

        @param reason: Reason this request has failed.
        @type reason: L{twisted.python.failure.Failure}

        @return: The reason passed to this method.
        @rtype: L{twisted.python.failure.Failure}
        """
        self._log.failure('', failure=reason)
        if self.site.displayTracebacks:
            body = (b"<html><head><title>web.Server Traceback"
                    b" (most recent call last)</title></head>"
                    b"<body><b>web.Server Traceback"
                    b" (most recent call last):</b>\n\n" +
                    util.formatFailure(reason) +
                    b"\n\n</body></html>\n")
        else:
            body = (b"<html><head><title>Processing Failed"
                    b"</title></head><body>"
                    b"<b>Processing Failed</b></body></html>")

        self.setResponseCode(http.INTERNAL_SERVER_ERROR)
        self.setHeader(b'content-type', b"text/html")
        self.setHeader(b'content-length', intToBytes(len(body)))
        self.write(body)
        self.finish()
        return reason
Exemplo n.º 9
0
    def failed(self, why):
        # if isinstance(why, pb.CopiedFailure): # a remote exception might
        # only have short traceback, so formatFailure is not as useful as
        # you'd like (no .frames, so no traceback is displayed)
        log.msg("BuildStep.failed, traceback follows")
        log.err(why)
        try:
            if self.progress:
                self.progress.finish()
            self.addHTMLLog("err.html", formatFailure(why))
            self.addCompleteLog("err.text", why.getTraceback())
            # could use why.getDetailedTraceback() for more information
            self.step_status.setText([self.name, "exception"])
            self.step_status.setText2([self.name])
            self.step_status.stepFinished(EXCEPTION)
        except:
            log.msg("exception during failure processing")
            log.err()
            # the progress stuff may still be whacked (the StepStatus may
            # think that it is still running), but the build overall will now
            # finish
        try:
            self.releaseLocks()
        except:
            log.msg("exception while releasing locks")
            log.err()

        log.msg("BuildStep.failed now firing callback")
        self.deferred.callback(EXCEPTION)
Exemplo n.º 10
0
    def _get_error_body(self, request, failure):
        if self.debug_handler and self.debug_handler.is_client_allowed_debugging(request):
            ajax_endpoint = request.childLink("__debug__/" + self.debug_handler.register_failure(failure))

            debug_variables = dict(ajax_endpoint=ajax_endpoint, body=web_util.formatFailure(failure))

            html = DEBUG_HTML_TEMPLATE % debug_variables
            return html

        return STANDARD_HTML_TEMPLATE
Exemplo n.º 11
0
 def processingFailed(self, reason):
     log.err(reason)
     body = ("<html><head><title>web.Server Traceback (most recent call last)</title></head>"
             "<body><b>web.Server Traceback (most recent call last):</b>\n\n"
             "%s\n\n</body></html>\n"
             % webutil.formatFailure(reason))
     self.setResponseCode(http.INTERNAL_SERVER_ERROR)
     self.setHeader('content-type',"text/html")
     self.setHeader('content-length', str(len(body)))
     self.write(body)
     self.finish()
     return reason
Exemplo n.º 12
0
    def test_returnsBytes(self):
        """
        The return value of L{formatFailure} is a C{str} instance (not a
        C{unicode} instance) with numeric character references for any non-ASCII
        characters meant to appear in the output.
        """
        try:
            raise Exception("Fake bug")
        except:
            result = formatFailure(Failure())

        self.assertIsInstance(result, bytes)
        self.assertTrue(all(ch < 128 for ch in result))
        # Indentation happens to rely on NO-BREAK SPACE
        self.assertIn(b"&#160;", result)
Exemplo n.º 13
0
    def test_returnsBytes(self):
        """
        The return value of L{formatFailure} is a C{str} instance (not a
        C{unicode} instance) with numeric character references for any non-ASCII
        characters meant to appear in the output.
        """
        try:
            raise Exception("Fake bug")
        except:
            result = formatFailure(Failure())

        self.assertIsInstance(result, str)
        self.assertTrue(all(ord(ch) < 128 for ch in result))
        # Indentation happens to rely on NO-BREAK SPACE
        self.assertIn("&#160;", result)
Exemplo n.º 14
0
    def processingFailed(self, reason):
        log.err(reason)
        if self.site.displayTracebacks:
            body = (
                "<html><head><title>web.Server Traceback (most recent call last)</title></head>"
                "<body><b>web.Server Traceback (most recent call last):</b>\n\n"
                "%s\n\n</body></html>\n" % webutil.formatFailure(reason))
        else:
            body = ("<html><head><title>Processing Failed</title></head><body>"
                    "<b>Processing Failed</b></body></html>")

        self.setResponseCode(http.INTERNAL_SERVER_ERROR)
        self.setHeader('content-type', "text/html")
        self.setHeader('content-length', str(len(body)))
        self.write(body)
        self.finish()
        return reason
Exemplo n.º 15
0
    def failed(self, why):
        # This can either be a BuildStepFailed exception/failure, meaning we
        # should call self.finished, or it can be a real exception, which should
        # be recorded as such.
        if why.check(BuildStepFailed):
            self.finished(FAILURE)
            return
        # However, in the case of losing the connection to a slave, we want to
        # finish with a RETRY.
        if why.check(error.ConnectionLost):
            self.step_status.setText(self.describe(True) +
                                     ["exception", "slave", "lost"])
            self.step_status.setText2(["exception", "slave", "lost"])
            self.finished(RETRY)
            return

        log.err(why, "BuildStep.failed; traceback follows")
        try:
            if self.progress:
                self.progress.finish()
            try:
                self.addCompleteLog("err.text", why.getTraceback())
                self.addHTMLLog("err.html", formatFailure(why))
            except Exception:
                log.err(Failure(), "error while formatting exceptions")

            # could use why.getDetailedTraceback() for more information
            self.step_status.setText([self.name, "exception"])
            self.step_status.setText2([self.name])
            self.step_status.stepFinished(EXCEPTION)

            hidden = self._maybeEvaluate(self.hideStepIf, EXCEPTION, self)
            self.step_status.setHidden(hidden)
        except Exception:
            log.err(Failure(), "exception during failure processing")
            # the progress stuff may still be whacked (the StepStatus may
            # think that it is still running), but the build overall will now
            # finish

        try:
            self.releaseLocks()
        except Exception:
            log.err(Failure(), "exception while releasing locks")

        log.msg("BuildStep.failed now firing callback")
        self.deferred.callback(EXCEPTION)
Exemplo n.º 16
0
    def failed(self, why):
        # This can either be a BuildStepFailed exception/failure, meaning we
        # should call self.finished, or it can be a real exception, which should
        # be recorded as such.
        if why.check(BuildStepFailed):
            self.finished(FAILURE)
            return

        klog.err_json(why, "BuildStep.failed; traceback follows")
        results = EXCEPTION
        try:
            if self.progress:
                self.progress.finish()
            try:
                self.addCompleteLog("err.text", why.getTraceback())
                self.addHTMLLog("err.html", formatFailure(why))
            except AttributeError:
                klog.err_json(
                    Failure(), "DEBUG formatting exc. why.type: %s %s" %
                    (why.type, type(why.type)))
            except Exception:
                klog.err_json(Failure(), "error while formatting exceptions")

            # could use why.getDetailedTraceback() for more information
            self.step_status.setText(["'%s'" % self.name, "exception"])
            self.step_status.setText2(["'%s'" % self.name])
            if isinstance(why, Failure) and (why.type == pb.PBConnectionLost or
                                             why.type == error.ConnectionLost):
                results = RETRY
            self.step_status.stepFinished(results)

            hidden = self._maybeEvaluate(self.hideStepIf, EXCEPTION, self)
            self.step_status.setHidden(hidden)
        except Exception:
            klog.err_json(Failure(), "exception during failure processing")
            # the progress stuff may still be whacked (the StepStatus may
            # think that it is still running), but the build overall will now
            # finish

        try:
            self.releaseLocks()
        except Exception:
            klog.err_json(Failure(), "exception while releasing locks")

        log.msg("BuildStep.failed now firing callback")
        self.deferred.callback(results)
Exemplo n.º 17
0
    def processingFailed(self, reason):
        log.err(reason)
        # Re-enable on Python 3 as part of #6178:
        if not _PY3 and self.site.displayTracebacks:
            body = ("<html><head><title>web.Server Traceback (most recent call last)</title></head>"
                    "<body><b>web.Server Traceback (most recent call last):</b>\n\n"
                    "%s\n\n</body></html>\n"
                    % webutil.formatFailure(reason))
        else:
            body = (b"<html><head><title>Processing Failed</title></head><body>"
                    b"<b>Processing Failed</b></body></html>")

        self.setResponseCode(http.INTERNAL_SERVER_ERROR)
        self.setHeader(b'content-type', b"text/html")
        self.setHeader(b'content-length', intToBytes(len(body)))
        self.write(body)
        self.finish()
        return reason
Exemplo n.º 18
0
    def processingFailed(self, reason):
        log.err(reason)
        # Re-enable on Python 3 as part of #6178:
        if not _PY3 and self.site.displayTracebacks:
            body = ("<html><head><title>web.Server Traceback (most recent call last)</title></head>"
                    "<body><b>web.Server Traceback (most recent call last):</b>\n\n"
                    "%s\n\n</body></html>\n"
                    % webutil.formatFailure(reason))
        else:
            body = (b"<html><head><title>Processing Failed</title></head><body>"
                    b"<b>Processing Failed</b></body></html>")

        self.setResponseCode(http.INTERNAL_SERVER_ERROR)
        self.setHeader(b'content-type', b"text/html")
        self.setHeader(b'content-length', intToBytes(len(body)))
        self.write(body)
        self.finish()
        return reason
Exemplo n.º 19
0
    def _finishFinished(self, results):
        # internal function to indicate that this step is done; this is separated
        # from finished() so that subclasses can override finished()
        if self.progress:
            self.progress.finish()

        try:
            hidden = self._maybeEvaluate(self.hideStepIf, results, self)
        except Exception:
            why = Failure()
            self.addHTMLLog("err.html", formatFailure(why))
            self.addCompleteLog("err.text", why.getTraceback())
            results = EXCEPTION
            hidden = False

        self.step_status.stepFinished(results)
        self.step_status.setHidden(hidden)

        self.releaseLocks()
        self.deferred.callback(results)
Exemplo n.º 20
0
    def _finishFinished(self, results):
        # internal function to indicate that this step is done; this is separated
        # from finished() so that subclasses can override finished()
        if self.progress:
            self.progress.finish()

        try:
            hidden = self._maybeEvaluate(self.hideStepIf, results, self)
        except Exception:
            why = Failure()
            self.addHTMLLog("err.html", formatFailure(why))
            self.addCompleteLog("err.text", why.getTraceback())
            results = EXCEPTION
            hidden = False

        self.step_status.stepFinished(results)
        self.step_status.setHidden(hidden)

        self.releaseLocks()
        self.deferred.callback(results)
Exemplo n.º 21
0
    def processingFailed(self, reason):
        log.err(reason)
        if self.site.displayTracebacks:
            body = (b"<html><head><title>web.Server Traceback"
                    b" (most recent call last)</title></head>"
                    b"<body><b>web.Server Traceback"
                    b" (most recent call last):</b>\n\n" +
                    util.formatFailure(reason) +
                    b"\n\n</body></html>\n")
        else:
            body = (b"<html><head><title>Processing Failed"
                    b"</title></head><body>"
                    b"<b>Processing Failed</b></body></html>")

        self.setResponseCode(http.INTERNAL_SERVER_ERROR)
        self.setHeader(b'content-type', b"text/html")
        self.setHeader(b'content-length', intToBytes(len(body)))
        self.write(body)
        self.finish()
        return reason
Exemplo n.º 22
0
    def mailFailure(self, event):
        if not event['isError']:
            return

        body = None
        if 'failure' in event:
            body = (
                "<html><head><title>EPP Proxy Traceback (most recent call last)</title></head>"
                "<body><b>EPP Proxy Traceback (most recent call last):</b>\n\n"
                "%s\n\n</body></html>\n" %
                webutil.formatFailure(event['failure']))
        else:
            body = str(event['message'])

        msg = MIMEMultipart()
        msg['From'] = conf.MAIL_FROM
        msg['To'] = ','.join(conf.MAIL_TO_ON_ERROR)
        #msg['Date'] = email_utils.formatdate()
        if 'failure' in event:
            msg['Subject'] = self.hostname + ' - EPP Proxy Failure'
        else:
            msg['Subject'] = self.hostname + ' - EPP Proxy Message'
        html_part = MIMEBase('text', 'html')
        html_part.set_payload(body)
        msg.attach(html_part)
        msg_data = msg.as_string(unixfrom=False)

        def _success(ignore):
            pass

        def _fail(reason):
            pass

        d = smtp.sendmail(conf.SMTP_HOST, conf.MAIL_FROM,
                          conf.MAIL_TO_ON_ERROR, msg_data)
        d.addCallbacks(_success, _fail)
Exemplo n.º 23
0
def renderFailure(fail, request):
    if not fail:
        fail = failure.Failure()
    log.err(fail)
    request.write(webutil.formatFailure(fail))
Exemplo n.º 24
0
def renderFailure(fail, request):
    if not fail:
        fail = failure.Failure()
    log.err(fail)
    request.write(webutil.formatFailure(fail))
Exemplo n.º 25
0
 def addErrorResult(self, why):
     self.addHTMLLog("err.html", formatFailure(why))
     self.addCompleteLog("err.text", why.getTraceback())
     results = EXCEPTION
     hidden = False
     return hidden, results
Exemplo n.º 26
0
		
		start_response('503 Service Unavailable', headers)
		return content
	except:
		reason = failure.Failure()
		reason.printTraceback(env['wsgi.errors'])
		if('modu.app' in req and req.app.config.get('error_content')):
			content_provider = req.app.error_content()
			req['modu.failure'] = reason
			content_provider.prepare_content(req)
			content = [content_provider.get_content(req)]
			headers = [('Content-Type', content_provider.get_content_type(req))]
		else:
			content = ["<html><head><title>web.Server Traceback (most recent call last)</title></head>"
				"<body><b>web.Server Traceback (most recent call last):</b>\n\n"
				"%s\n\n</body></html>\n" % util.formatFailure(reason)]
			headers = [('Content-Type', 'text/html')]
		
		start_response('500 Internal Server Error', headers)
		return content
	
	start_response('200 OK', req.get_headers())
	return content

def check_maintenance_mode(req):
	"""
	Check whether maintenance mode is on or not.
	
	At this time, this merely checks for the existence of a 'modu-maintenance' file
	in /etc. There are a significant limitations with this implementation: