pretty (Rack::ShowExceptions)

    # File lib/rack/showexceptions.rb, line 32
        def pretty(env, exception)
          req = Rack::Request.new(env)
          path = (req.script_name + req.path_info).squeeze("/")

          frames = exception.backtrace.map { |line|
            frame = OpenStruct.new
            if line =~ /(.*?):(\d+)(:in `(.*)')?/
              frame.filename = $1
              frame.lineno = $2.to_i
              frame.function = $4

              begin
                lineno = frame.lineno-1
                lines = ::File.readlines(frame.filename)
                frame.pre_context_lineno = [lineno-CONTEXT, 0].max
                frame.pre_context = lines[frame.pre_context_lineno...lineno]
                frame.context_line = lines[lineno].chomp
                frame.post_context_lineno = [lineno+CONTEXT, lines.size].min
                frame.post_context = lines[lineno+1..frame.post_context_lineno]
              rescue
              end

              frame
            else
              nil
            end
          }.compact

          env["rack.errors"].puts "#{exception.class}: #{exception.message}"
          env["rack.errors"].puts exception.backtrace.map { |l| "\t" + l }
          env["rack.errors"].flush

          [@template.result(binding)]
        end