Пример #1
0
    def _report_errors(self, environ, start_response):
        context = RequestContext({'environ': dict(environ)})
        for injector in self.context_injectors:
            context.update(injector(environ))
        traceback = get_current_traceback(skip=2, show_hidden_frames=False, context=context)

        try:
            start_response('500 INTERNAL SERVER ERROR', [
                ('Content-Type', 'text/html; charset=utf-8'),
                # Disable Chrome's XSS protection, the debug
                # output can cause false-positives.
                ('X-XSS-Protection', '0'),
                ])
        except Exception:
            # if we end up here there has been output but an error
            # occurred.  in that situation we can do nothing fancy any
            # more, better log something into the error log and fall
            # back gracefully.
            environ['wsgi.errors'].write(
                'Debugging middleware caught exception in streamed '
                'response at a point where response headers were already '
                'sent.\n')
        else:
            yield bytes_('Internal Server Error')

        traceback.log(environ['wsgi.errors'])

        for r in self.reporters:
            try:
                r.report(traceback)
            except Exception:
                error = get_current_traceback(skip=1, show_hidden_frames=False)
                environ['wsgi.errors'].write('\nError while reporting exception with %s\n' % r)
                environ['wsgi.errors'].write(error.plaintext)
 def call(controller, *args, **kw):
     try:
         return method(controller, *args, **kw)
     except Exception as e:
         tb = get_current_traceback()
         tb.log()
         return error_handler(controller, e)
Пример #3
0
    def peek(self, environ, thread_id, started):
        context = RequestContext({'environ': dict(environ)})
        for injector in self.context_injectors:
            context.update(injector(environ))

        context.update({
            'SLOW_REQUEST': {
                'ThreadID': thread_id,
                'ProcessID': os.getpid(),
                'Started': str(started)
            }
        })

        try:
            traceback = get_thread_stack(thread_id,
                                         environ.get('PATH_INFO', ''),
                                         context=context,
                                         error_type='SlowRequestError')
        except KeyError:
            logging.warn(
                '\nUnable to retrieve SlowRequest Stack %s, '
                'thread %s probably finished execution in mean time\n',
                environ.get('PATH_INFO', ''), thread_id)
            return

        for r in self.reporters:
            try:
                r.report(traceback)
            except Exception:
                error = get_current_traceback(skip=1, show_hidden_frames=False)
                environ['wsgi.errors'].write(
                    '\nError while reporting slow request with %s\n' % r)
                environ['wsgi.errors'].write(error.plaintext)
Пример #4
0
    def _report_errors(self, environ, recorded_exc_info=None):
        context = RequestContext({'environ': dict(environ)})
        for injector in self.context_injectors:
            context.update(injector(environ))

        traceback = get_current_traceback(skip=2, show_hidden_frames=False, context=context,
                                          exc_info=recorded_exc_info)
        traceback.log(environ['wsgi.errors'])

        for r in self.reporters:
            try:
                r.report(traceback)
            except Exception:
                error = get_current_traceback(skip=1, show_hidden_frames=False)
                environ['wsgi.errors'].write('\nError while reporting exception with %s\n' % r)
                environ['wsgi.errors'].write(error.plaintext)
Пример #5
0
    def peek(self, environ, thread_id, started):
        context = RequestContext({"environ": dict(environ)})
        for injector in self.context_injectors:
            context.update(injector(environ))

        context.update({"SLOW_REQUEST": {"ThreadID": thread_id, "ProcessID": os.getpid(), "Started": str(started)}})

        try:
            traceback = get_thread_stack(
                thread_id, environ.get("PATH_INFO", ""), context=context, error_type="SlowRequestError"
            )
        except KeyError:
            logging.warn(
                "\nUnable to retrieve SlowRequest Stack %s, " "thread %s probably finished execution in mean time\n",
                environ.get("PATH_INFO", ""),
                thread_id,
            )
            return

        for r in self.reporters:
            try:
                r.report(traceback)
            except Exception:
                error = get_current_traceback(skip=1, show_hidden_frames=False)
                environ["wsgi.errors"].write("\nError while reporting slow request with %s\n" % r)
                environ["wsgi.errors"].write(error.plaintext)
Пример #6
0
 def _cancel_tracing(self, environ):
     try:
         tracing_jobs = environ.get("BACKLASH_SLOW_TRACING_JOBS", [])
         for job in tracing_jobs:
             self.timer.cancel(job)
     except Exception:
         error = get_current_traceback(skip=1, show_hidden_frames=False)
         environ["wsgi.errors"].write("Failed to cancel slow requests tracing timer\n")
         environ["wsgi.errors"].write(error.plaintext)
Пример #7
0
 def _cancel_tracing(self, environ):
     try:
         tracing_jobs = environ.get('BACKLASH_SLOW_TRACING_JOBS', [])
         for job in tracing_jobs:
             self.timer.cancel(job)
     except Exception:
         error = get_current_traceback(skip=1, show_hidden_frames=False)
         environ['wsgi.errors'].write(
             'Failed to cancel slow requests tracing timer\n')
         environ['wsgi.errors'].write(error.plaintext)
Пример #8
0
    def _report_errors(self, environ, recorded_exc_info=None):
        context = RequestContext({'environ': dict(environ)})
        for injector in self.context_injectors:
            context.update(injector(environ))

        traceback = get_current_traceback(skip=2,
                                          show_hidden_frames=False,
                                          context=context,
                                          exc_info=recorded_exc_info)
        traceback.log(environ['wsgi.errors'])

        for r in self.reporters:
            try:
                r.report(traceback)
            except Exception:
                error = get_current_traceback(skip=1, show_hidden_frames=False)
                environ['wsgi.errors'].write(
                    '\nError while reporting exception with %s\n' % r)
                environ['wsgi.errors'].write(error.plaintext)
Пример #9
0
    def _report_errors(self, environ, recorded_exc_info=None):
        context = RequestContext({'environ': dict(environ)})
        for injector in self.context_injectors:
            context.update(injector(environ))

        traceback = get_current_traceback(skip=2, show_hidden_frames=False, context=context,
                                          exc_info=recorded_exc_info)

        # This will lead to double logging in case backlash logger is set to DEBUG
        # but this is actually wanted as some environments, like WebTest, swallow
        # wsgi.environ making the traceback totally disappear.
        log.debug(traceback.plaintext)
        traceback.log(environ['wsgi.errors'])

        for r in self.reporters:
            try:
                r.report(traceback)
            except Exception:
                error = get_current_traceback(skip=1, show_hidden_frames=False)
                environ['wsgi.errors'].write('\nError while reporting exception with %s\n' % r)
                environ['wsgi.errors'].write(error.plaintext)
Пример #10
0
    def _report_errors(self, environ, start_response):
        context = RequestContext({'environ': dict(environ)})
        for injector in self.context_injectors:
            context.update(injector(environ))
        traceback = get_current_traceback(skip=2,
                                          show_hidden_frames=False,
                                          context=context)

        try:
            start_response(
                '500 INTERNAL SERVER ERROR',
                [
                    ('Content-Type', 'text/html; charset=utf-8'),
                    # Disable Chrome's XSS protection, the debug
                    # output can cause false-positives.
                    ('X-XSS-Protection', '0'),
                ])
        except Exception:
            # if we end up here there has been output but an error
            # occurred.  in that situation we can do nothing fancy any
            # more, better log something into the error log and fall
            # back gracefully.
            environ['wsgi.errors'].write(
                'Debugging middleware caught exception in streamed '
                'response at a point where response headers were already '
                'sent.\n')
        else:
            yield bytes_('Internal Server Error')

        traceback.log(environ['wsgi.errors'])

        for r in self.reporters:
            try:
                r.report(traceback)
            except Exception:
                error = get_current_traceback(skip=1, show_hidden_frames=False)
                environ['wsgi.errors'].write(
                    '\nError while reporting exception with %s\n' % r)
                environ['wsgi.errors'].write(error.plaintext)
Пример #11
0
    def debug_application(self, environ, start_response):
        """Run the application and conserve the traceback frames."""
        app_iter = None
        try:
            app_iter = self.app(environ, start_response)
            for item in app_iter:
                yield item
            if hasattr(app_iter, 'close'):
                app_iter.close()
        except Exception:
            if hasattr(app_iter, 'close'):
                app_iter.close()

            context = RequestContext({'environ':dict(environ)})
            for injector in self.context_injectors:
                context.update(injector(environ))

            traceback = get_current_traceback(skip=1, show_hidden_frames=self.show_hidden_frames,
                                              context=context)
            for frame in traceback.frames:
                self.frames[frame.id] = frame
            self.tracebacks[traceback.id] = traceback

            try:
                start_response('500 INTERNAL SERVER ERROR', [
                    ('Content-Type', 'text/html; charset=utf-8'),
                    # Disable Chrome's XSS protection, the debug
                    # output can cause false-positives.
                    ('X-XSS-Protection', '0'),
                    ])
            except Exception:
                # if we end up here there has been output but an error
                # occurred.  in that situation we can do nothing fancy any
                # more, better log something into the error log and fall
                # back gracefully.
                environ['wsgi.errors'].write(
                    'Debugging middleware caught exception in streamed '
                    'response at a point where response headers were already '
                    'sent.\n')
            else:
                yield traceback.render_full(
                    evalex=self.evalex,
                    secret=self.secret
                ).encode('utf-8', 'replace')

            # This will lead to double logging in case backlash logger is set to DEBUG
            # but this is actually wanted as some environments, like WebTest, swallow
            # wsgi.environ making the traceback totally disappear.
            log.debug(traceback.plaintext)
            traceback.log(environ['wsgi.errors'])
Пример #12
0
    def _report_errors(self, environ, recorded_exc_info=None):
        context = RequestContext({'environ': dict(environ)})
        for injector in self.context_injectors:
            context.update(injector(environ))

        traceback = get_current_traceback(skip=2,
                                          show_hidden_frames=False,
                                          context=context,
                                          exc_info=recorded_exc_info)

        # This will lead to double logging in case backlash logger is set to DEBUG
        # but this is actually wanted as some environments, like WebTest, swallow
        # wsgi.environ making the traceback totally disappear.
        log.debug(traceback.plaintext)
        traceback.log(environ['wsgi.errors'])

        for r in self.reporters:
            try:
                r.report(traceback)
            except Exception:
                error = get_current_traceback(skip=1, show_hidden_frames=False)
                environ['wsgi.errors'].write(
                    '\nError while reporting exception with %s\n' % r)
                environ['wsgi.errors'].write(error.plaintext)
Пример #13
0
 def showsyntaxerror(self, filename=None):
     from backlash.tbtools import get_current_traceback
     tb = get_current_traceback(skip=4)
     sys.stdout._write(tb.render_summary())
Пример #14
0
 def showtraceback(self):
     from backlash.tbtools import get_current_traceback
     tb = get_current_traceback(skip=1)
     sys.stdout._write(tb.render_summary())
Пример #15
0
 def showsyntaxerror(self, filename=None):
     from backlash.tbtools import get_current_traceback
     tb = get_current_traceback(skip=4)
     sys.stdout._write(tb.render_summary())
Пример #16
0
 def showtraceback(self):
     from backlash.tbtools import get_current_traceback
     tb = get_current_traceback(skip=1)
     sys.stdout._write(tb.render_summary())