class BetterErrors::ErrorPage
@private
Attributes
env[R]
exception[R]
repls[R]
Public Class Methods
new(exception, env)
click to toggle source
# File lib/better_errors/error_page.rb, line 18 def initialize(exception, env) @exception = RaisedException.new(exception) @env = env @start_time = Time.now.to_f @repls = [] end
template(template_name)
click to toggle source
# File lib/better_errors/error_page.rb, line 12 def self.template(template_name) Erubis::EscapedEruby.new(File.read(template_path(template_name))) end
template_path(template_name)
click to toggle source
# File lib/better_errors/error_page.rb, line 8 def self.template_path(template_name) File.expand_path("../templates/#{template_name}.erb", __FILE__) end
Public Instance Methods
application_frames()
click to toggle source
# File lib/better_errors/error_page.rb, line 69 def application_frames backtrace_frames.select(&:application?) end
backtrace_frames()
click to toggle source
# File lib/better_errors/error_page.rb, line 57 def backtrace_frames exception.backtrace end
do_eval(opts)
click to toggle source
# File lib/better_errors/error_page.rb, line 40 def do_eval(opts) index = opts["index"].to_i code = opts["source"] unless binding = backtrace_frames[index].frame_binding return { error: "REPL unavailable in this stack frame" } end result, prompt, prefilled_input = (@repls[index] ||= REPL.provider.new(binding)).send_input(code) { result: result, prompt: prompt, prefilled_input: prefilled_input, highlighted_input: CodeRay.scan(code, :ruby).div(wrap: nil) } end
do_variables(opts)
click to toggle source
# File lib/better_errors/error_page.rb, line 33 def do_variables(opts) index = opts["index"].to_i @frame = backtrace_frames[index] @var_start_time = Time.now.to_f { html: render("variable_info") } end
exception_message()
click to toggle source
# File lib/better_errors/error_page.rb, line 65 def exception_message exception.message.lstrip end
exception_type()
click to toggle source
# File lib/better_errors/error_page.rb, line 61 def exception_type exception.type end
first_frame()
click to toggle source
# File lib/better_errors/error_page.rb, line 73 def first_frame application_frames.first || backtrace_frames.first end
id()
click to toggle source
# File lib/better_errors/error_page.rb, line 25 def id @id ||= SecureRandom.hex(8) end
render(template_name = "main")
click to toggle source
# File lib/better_errors/error_page.rb, line 29 def render(template_name = "main") self.class.template(template_name).result binding end
Private Instance Methods
editor_url(frame)
click to toggle source
# File lib/better_errors/error_page.rb, line 78 def editor_url(frame) BetterErrors.editor[frame.filename, frame.line] end
html_formatted_code_block(frame)
click to toggle source
# File lib/better_errors/error_page.rb, line 98 def html_formatted_code_block(frame) CodeFormatter::HTML.new(frame.filename, frame.line).output end
inspect_raw_value(obj)
click to toggle source
# File lib/better_errors/error_page.rb, line 118 def inspect_raw_value(obj) value = CGI.escapeHTML(obj.inspect) if !BetterErrors.maximum_variable_inspect_size.nil? && value.length > BetterErrors.maximum_variable_inspect_size value = "<span class='unsupported'>(object too large - modify #{CGI.escapeHTML(obj.class.to_s)}#inspect or raise BetterErrors.maximum_variable_inspect_size)</span>" end value end
inspect_value(obj)
click to toggle source
# File lib/better_errors/error_page.rb, line 110 def inspect_value(obj) inspect_raw_value(obj) rescue NoMethodError "<span class='unsupported'>(object doesn't support inspect)</span>" rescue Exception => e "<span class='unsupported'>(exception #{CGI.escapeHTML(e.class.to_s)} was raised in inspect)</span>" end
rack_session()
click to toggle source
# File lib/better_errors/error_page.rb, line 82 def rack_session env['rack.session'] end
rails_params()
click to toggle source
# File lib/better_errors/error_page.rb, line 86 def rails_params env['action_dispatch.request.parameters'] end
request_path()
click to toggle source
# File lib/better_errors/error_page.rb, line 94 def request_path env["PATH_INFO"] end
text_formatted_code_block(frame)
click to toggle source
# File lib/better_errors/error_page.rb, line 102 def text_formatted_code_block(frame) CodeFormatter::Text.new(frame.filename, frame.line).output end
text_heading(char, str)
click to toggle source
# File lib/better_errors/error_page.rb, line 106 def text_heading(char, str) str + "\n" + char*str.size end
uri_prefix()
click to toggle source
# File lib/better_errors/error_page.rb, line 90 def uri_prefix env["SCRIPT_NAME"] || "" end