Rack::ShowExceptions catches all exceptions raised from the app it wraps. It shows a useful backtrace with the sourcefile and clickable context, the whole Rack environment and the request data.
Be careful when you use this on public-facing sites as it could reveal information helpful to attackers.
# File lib/rack/showexceptions.rb, line 23 23: def call(env) 24: @app.call(env) 25: rescue StandardError, LoadError, SyntaxError => e 26: backtrace = pretty(env, e) 27: [500, 28: {"Content-Type" => "text/html", 29: "Content-Length" => backtrace.join.size.to_s}, 30: backtrace] 31: end
# File lib/rack/showexceptions.rb, line 33 33: def pretty(env, exception) 34: req = Rack::Request.new(env) 35: path = (req.script_name + req.path_info).squeeze("/") 36: 37: frames = exception.backtrace.map { |line| 38: frame = OpenStruct.new 39: if line =~ /(.*?):(\d+)(:in `(.*)')?/ 40: frame.filename = $1 41: frame.lineno = $2.to_i 42: frame.function = $4 43: 44: begin 45: lineno = frame.lineno-1 46: lines = ::File.readlines(frame.filename) 47: frame.pre_context_lineno = [lineno-CONTEXT, 0].max 48: frame.pre_context = lines[frame.pre_context_lineno...lineno] 49: frame.context_line = lines[lineno].chomp 50: frame.post_context_lineno = [lineno+CONTEXT, lines.size].min 51: frame.post_context = lines[lineno+1..frame.post_context_lineno] 52: rescue 53: end 54: 55: frame 56: else 57: nil 58: end 59: }.compact 60: 61: env["rack.errors"].puts "#{exception.class}: #{exception.message}" 62: env["rack.errors"].puts exception.backtrace.map { |l| "\t" + l } 63: env["rack.errors"].flush 64: 65: [@template.result(binding)] 66: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.