Kiss A simpler, smarter web application framework for Ruby

Kiss::ExceptionReport Subclass of Object

Description

Generates HTML reports on exceptions raised from the app, showing the backtrace with clickable stack frames with TextMate links to source files, plus login hash, last SQL, GET/POST params, cookies, and Rack environment variables.

Public Class Methods

generate(exception, env = nil, cache = nil, sql = nil) source

Not documented

    # File lib/kiss/exception_report.rb, line 10
      def generate(exception, env = nil, cache = nil, sql = nil)
        if env
          req = Rack::Request.new(env)
          path = (req.script_name + req.path_info).squeeze("/")
          url = (req.scheme + '://' + req.host + path) rescue 'n/a'
        end
      
        backtrace = exception.backtrace
        #backtrace.shift while (backtrace[0] =~ /\/lib\/kiss(\/|\.rb)/) || (backtrace[0] =~ /\/lib\/sequel/)
        
        frames = backtrace.map { |line|
          frame = {}
          if line =~ /(.*?):(\d+)(:in `(.*)')?/
            frame.filename = $1
            frame.lineno = $2.to_i
            frame.function = $4
            lines = nil
            
            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
        
        if env
          env["rack.errors"].puts "#{exception.class}: #{exception.message}"
          env["rack.errors"].puts exception.backtrace.map { |l| "\t" + l }
          env["rack.errors"].flush
        end
        
        db_query = begin (Sequel::MySQL::Database.last_query) rescue nil end
        
        @@erubis ||= Erubis::Eruby.new(template)
        @@erubis.result(binding)
      end
    
h(*args) source

Not documented

    # File lib/kiss/exception_report.rb, line 65
      def h(*args)
        Kiss.html_escape(*args)
      end
    
textmate_href(frame) source

Not documented

    # File lib/kiss/exception_report.rb, line 57
      def textmate_href(frame)
        "txmt://open?url=file://"+(h(Kiss.absolute_path(frame.filename)))+"&line="+(h frame.lineno)
      end
    
w(str) source

Not documented

    # File lib/kiss/exception_report.rb, line 61
      def w(str)
        str.gsub(/([;\/])/,'\1<wbr/>')
      end
    

Disabled; run with $DEBUG to generate this.