# frozen_string_literal: true require 'rack/show_exceptions' module Sinatra # Sinatra::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. class ShowExceptions < Rack::ShowExceptions @@eats_errors = Object.new def @@eats_errors.flush(*) end def @@eats_errors.puts(*) end def initialize(app) @app = app end def call(env) @app.call(env) rescue Exception => e errors = env['rack.errors'] env['rack.errors'] = @@eats_errors if prefers_plain_text?(env) content_type = 'text/plain' body = dump_exception(e) else content_type = 'text/html' body = pretty(env, e) end env['rack.errors'] = errors [ 500, { 'content-type' => content_type, 'content-length' => body.bytesize.to_s }, [body] ] end def template TEMPLATE end private def bad_request?(exception) Sinatra::BadRequest === exception end def prefers_plain_text?(env) Request.new(env).preferred_type('text/plain', 'text/html') != 'text/html' && [/curl/].index { |item| item =~ env['HTTP_USER_AGENT'] } end def frame_class(frame) if frame.filename =~ %r{lib/sinatra.*\.rb} 'framework' elsif (defined?(Gem) && frame.filename.include?(Gem.dir)) || frame.filename =~ %r{/bin/(\w+)\z} 'system' else 'app' end end TEMPLATE = ERB.new <<-HTML # :nodoc: <%=h exception.class %> at <%=h path %>

BACKTRACE

(expand)

<% unless bad_request?(exception) %>

GET

<% if req.GET and not req.GET.empty? %> <% req.GET.sort_by { |k, v| k.to_s }.each { |key, val| %> <% } %>
Variable Value
<%=h key %>
<%=h val.inspect %>
<% else %>

No GET data.

<% end %>

POST

<% if req.POST and not req.POST.empty? %> <% req.POST.sort_by { |k, v| k.to_s }.each { |key, val| %> <% } %>
Variable Value
<%=h key %>
<%=h val.inspect %>
<% else %>

No POST data.

<% end %>
<% end %>
<% unless req.cookies.empty? %> <% req.cookies.each { |key, val| %> <% } %>
Variable Value
<%=h key %>
<%=h val.inspect %>
<% else %>

No cookie data.

<% end %>

Rack ENV

<% env.sort_by { |k, v| k.to_s }.each { |key, val| %> <% } %>
Variable Value
<%=h key %>
<%=h val %>

You're seeing this error because you have enabled the show_exceptions setting.

HTML end end