base.rb
dump_errors!
/usr/local/bundle/gems/sinatra-3.0.6/lib/sinatra/base.rb
in
dump_errors!
return false unless key.respond_to?(:superclass) && (key.superclass < Exception)
error_block!(key.superclass, *block_params)
end
def dump_errors!(boom)
msg = ["#{Time.now.strftime('%Y-%m-%d %H:%M:%S')} - #{boom.class} - #{boom.message}:", *boom.backtrace].join("\n\t")
@env['rack.errors'].puts(msg)
end
class << self
CALLERS_TO_IGNORE = [ # :nodoc:
%r{/sinatra(/(base|main|show_exceptions))?\.rb$}, # all sinatra code
%r{lib/tilt.*\.rb$}, # all tilt code
/^\(.*\)$/, # generated code
/usr/local/bundle/gems/sinatra-3.0.6/lib/sinatra/base.rb
in
handle_exception!
end
end
http_status = 500 unless http_status&.between?(400, 599)
status(http_status)
if server_error?
dump_errors! boom if settings.dump_errors?
raise boom if settings.show_exceptions? && (settings.show_exceptions != :after_handler)
elsif not_found?
headers['X-Cascade'] = 'pass' if settings.x_cascade?
end
if (res = error_block!(boom.class, boom) || error_block!(status, boom))
return res
/usr/local/bundle/gems/sinatra-3.0.6/lib/sinatra/base.rb
in
block in dispatch!
static! if settings.static? && (request.get? || request.head?)
filter! :before do
@pinned_response = !response['Content-Type'].nil?
end
route!
end
rescue ::Exception => e
invoke { handle_exception!(e) }
ensure
begin
filter! :after unless env['sinatra.static_file']
rescue ::Exception => e
invoke { handle_exception!(e) } unless @env['sinatra.error']
end
end
/usr/local/bundle/gems/sinatra-3.0.6/lib/sinatra/base.rb
in
catch
env['sinatra.static_file'] = path
cache_control(*settings.static_cache_control) if settings.static_cache_control?
send_file path, options.merge(disposition: nil)
end
# Run the block with 'throw :halt' support and apply result to the response.
def invoke(&block)
res = catch(:halt, &block)
res = [res] if (Integer === res) || (String === res)
if (Array === res) && (Integer === res.first)
res = res.dup
status(res.shift)
body(res.pop)
headers(*res)
/usr/local/bundle/gems/sinatra-3.0.6/lib/sinatra/base.rb
in
invoke
env['sinatra.static_file'] = path
cache_control(*settings.static_cache_control) if settings.static_cache_control?
send_file path, options.merge(disposition: nil)
end
# Run the block with 'throw :halt' support and apply result to the response.
def invoke(&block)
res = catch(:halt, &block)
res = [res] if (Integer === res) || (String === res)
if (Array === res) && (Integer === res.first)
res = res.dup
status(res.shift)
body(res.pop)
headers(*res)
/usr/local/bundle/gems/sinatra-3.0.6/lib/sinatra/base.rb
in
rescue in dispatch!
static! if settings.static? && (request.get? || request.head?)
filter! :before do
@pinned_response = !response['Content-Type'].nil?
end
route!
end
rescue ::Exception => e
invoke { handle_exception!(e) }
ensure
begin
filter! :after unless env['sinatra.static_file']
rescue ::Exception => e
invoke { handle_exception!(e) } unless @env['sinatra.error']
end
end
/usr/local/bundle/gems/sinatra-3.0.6/lib/sinatra/base.rb
in
dispatch!
invoke do
static! if settings.static? && (request.get? || request.head?)
filter! :before do
@pinned_response = !response['Content-Type'].nil?
end
route!
end
rescue ::Exception => e
invoke { handle_exception!(e) }
ensure
begin
filter! :after unless env['sinatra.static_file']
rescue ::Exception => e
invoke { handle_exception!(e) } unless @env['sinatra.error']
end
/usr/local/bundle/gems/sinatra-3.0.6/lib/sinatra/base.rb
in
block in call!
@env = env
@params = IndifferentHash.new
@request = Request.new(env)
@response = Response.new
@pinned_response = nil
template_cache.clear if settings.reload_templates
invoke { dispatch! }
invoke { error_block!(response.status) } unless @env['sinatra.error']
unless @response['Content-Type']
if Array === body && body[0].respond_to?(:content_type)
content_type body[0].content_type
elsif (default = settings.default_content_type)
content_type default
/usr/local/bundle/gems/sinatra-3.0.6/lib/sinatra/base.rb
in
catch
env['sinatra.static_file'] = path
cache_control(*settings.static_cache_control) if settings.static_cache_control?
send_file path, options.merge(disposition: nil)
end
# Run the block with 'throw :halt' support and apply result to the response.
def invoke(&block)
res = catch(:halt, &block)
res = [res] if (Integer === res) || (String === res)
if (Array === res) && (Integer === res.first)
res = res.dup
status(res.shift)
body(res.pop)
headers(*res)
/usr/local/bundle/gems/sinatra-3.0.6/lib/sinatra/base.rb
in
invoke
env['sinatra.static_file'] = path
cache_control(*settings.static_cache_control) if settings.static_cache_control?
send_file path, options.merge(disposition: nil)
end
# Run the block with 'throw :halt' support and apply result to the response.
def invoke(&block)
res = catch(:halt, &block)
res = [res] if (Integer === res) || (String === res)
if (Array === res) && (Integer === res.first)
res = res.dup
status(res.shift)
body(res.pop)
headers(*res)
/usr/local/bundle/gems/sinatra-3.0.6/lib/sinatra/base.rb
in
call!
@env = env
@params = IndifferentHash.new
@request = Request.new(env)
@response = Response.new
@pinned_response = nil
template_cache.clear if settings.reload_templates
invoke { dispatch! }
invoke { error_block!(response.status) } unless @env['sinatra.error']
unless @response['Content-Type']
if Array === body && body[0].respond_to?(:content_type)
content_type body[0].content_type
elsif (default = settings.default_content_type)
content_type default
/usr/local/bundle/gems/sinatra-3.0.6/lib/sinatra/base.rb
in
call
@template_cache = Tilt::Cache.new
@pinned_response = nil # whether a before! filter pinned the content-type
yield self if block_given?
end
# Rack call interface.
def call(env)
dup.call!(env)
end
def call!(env) # :nodoc:
@env = env
@params = IndifferentHash.new
@request = Request.new(env)
@response = Response.new
/usr/local/bundle/gems/rack-protection-3.0.6/lib/rack/protection/xss_header.rb
in
call
#
# Options:
# xss_mode:: How the browser should prevent the attack (default: :block)
class XSSHeader < Base
default_options xss_mode: :block, nosniff: true
def call(env)
status, headers, body = @app.call(env)
headers['X-XSS-Protection'] ||= "1; mode=#{options[:xss_mode]}" if html? headers
headers['X-Content-Type-Options'] ||= 'nosniff' if options[:nosniff]
[status, headers, body]
end
end
end
end
/usr/local/bundle/gems/rack-protection-3.0.6/lib/rack/protection/path_traversal.rb
in
call
#
# Unescapes '/' and '.', expands +path_info+.
# Thus <tt>GET /foo/%2e%2e%2fbar</tt> becomes <tt>GET /bar</tt>.
class PathTraversal < Base
def call(env)
path_was = env['PATH_INFO']
env['PATH_INFO'] = cleanup path_was if path_was && !path_was.empty?
app.call env
ensure
env['PATH_INFO'] = path_was
end
def cleanup(path)
encoding = path.encoding
dot = '.'.encode(encoding)
/usr/local/bundle/gems/rack-protection-3.0.6/lib/rack/protection/json_csrf.rb
in
call
class JsonCsrf < Base
default_options allow_if: nil
alias react deny
def call(env)
request = Request.new(env)
status, headers, body = app.call(env)
if has_vector?(request, headers)
warn env, "attack prevented by #{self.class}"
react_and_close(env, body) or [status, headers, body]
else
[status, headers, body]
/usr/local/bundle/gems/rack-protection-3.0.6/lib/rack/protection/base.rb
in
call
end
def call(env)
unless accepts? env
instrument env
result = react env
end
result or app.call(env)
end
def react(env)
result = send(options[:reaction], env)
result if (Array === result) && (result.size == 3)
end
/usr/local/bundle/gems/rack-protection-3.0.6/lib/rack/protection/base.rb
in
call
end
def call(env)
unless accepts? env
instrument env
result = react env
end
result or app.call(env)
end
def react(env)
result = send(options[:reaction], env)
result if (Array === result) && (result.size == 3)
end
/usr/local/bundle/gems/rack-protection-3.0.6/lib/rack/protection/frame_options.rb
in
call
frame_options = options[:frame_options]
frame_options = options[:frame_options].to_s.upcase unless frame_options.respond_to? :to_str
frame_options.to_str
end
end
def call(env)
status, headers, body = @app.call(env)
headers['X-Frame-Options'] ||= frame_options if html? headers
[status, headers, body]
end
end
end
end
/usr/local/bundle/gems/rack-2.2.7/lib/rack/logger.rb
in
call
end
def call(env)
logger = ::Logger.new(env[RACK_ERRORS])
logger.level = @level
env[RACK_LOGGER] = logger
@app.call(env)
end
end
end
/usr/local/bundle/gems/rack-2.2.7/lib/rack/common_logger.rb
in
call
# will not be logged, so if exception handling middleware are used,
# they should be loaded after this middleware. Additionally, because
# the logging happens after the request body has been fully sent, any
# exceptions raised during the sending of the response body will
# cause the request not to be logged.
def call(env)
began_at = Utils.clock_time
status, headers, body = @app.call(env)
headers = Utils::HeaderHash[headers]
body = BodyProxy.new(body) { log(env, status, headers, began_at) }
[status, headers, body]
end
private
/usr/local/bundle/gems/sinatra-3.0.6/lib/sinatra/base.rb
in
call
env['sinatra.commonlogger'] ? @app.call(env) : super
end
superclass.class_eval do
alias_method :call_without_check, :call unless method_defined? :call_without_check
def call(env)
env['sinatra.commonlogger'] = true
call_without_check(env)
end
end
end
class Error < StandardError # :nodoc:
end
/usr/local/bundle/gems/sinatra-3.0.6/lib/sinatra/base.rb
in
call
end
end
# Behaves exactly like Rack::CommonLogger with the notable exception that it does nothing,
# if another CommonLogger is already in the middleware chain.
class CommonLogger < Rack::CommonLogger
def call(env)
env['sinatra.commonlogger'] ? @app.call(env) : super
end
superclass.class_eval do
alias_method :call_without_check, :call unless method_defined? :call_without_check
def call(env)
env['sinatra.commonlogger'] = true
call_without_check(env)
/usr/local/bundle/gems/rack-2.2.7/lib/rack/head.rb
in
call
# all other requests unchanged.
class Head
def initialize(app)
@app = app
end
def call(env)
status, headers, body = @app.call(env)
if env[REQUEST_METHOD] == HEAD
[
status, headers, Rack::BodyProxy.new([]) do
body.close if body.respond_to? :close
end
]
/usr/local/bundle/gems/rack-2.2.7/lib/rack/method_override.rb
in
call
method = method_override(env)
if HTTP_METHODS.include?(method)
env[RACK_METHODOVERRIDE_ORIGINAL_METHOD] = env[REQUEST_METHOD]
env[REQUEST_METHOD] = method
end
end
@app.call(env)
end
def method_override(env)
req = Request.new(env)
method = method_override_param(req) ||
env[HTTP_METHOD_OVERRIDE_HEADER]
begin
/usr/local/bundle/gems/sinatra-3.0.6/lib/sinatra/show_exceptions.rb
in
call
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)
/usr/local/bundle/gems/sinatra-3.0.6/lib/sinatra/base.rb
in
call
# Some Rack handlers (Rainbows!) implement an extended body object protocol, however,
# some middleware (namely Rack::Lint) will break it by not mirroring the methods in question.
# This middleware will detect an extended body object and will make sure it reaches the
# handler directly. We do this here, so our middleware and middleware set up by the app will
# still be able to run.
class ExtendedRack < Struct.new(:app)
def call(env)
result = app.call(env)
callback = env['async.callback']
return result unless callback && async?(*result)
after_response { callback.call result }
setup_close(env, *result)
throw :async
end
/usr/local/bundle/gems/sinatra-3.0.6/lib/sinatra/base.rb
in
call
end
def helpers
@instance
end
def call(env)
@stack.call(env)
end
def inspect
"#<#{@instance.class} app_file=#{settings.app_file.inspect}>"
end
end
/app/lib/generator.rb
in
render_html
end
def app
@app ||= Sinatra::Application.new
end
def render_html(path)
status, headers, body = app.call({
"PATH_INFO" => path,
"REQUEST_METHOD" => "GET",
"rack.input" => ""
})
body[0]
end
/app/lib/generator.rb
in
save
"rack.input" => ""
})
body[0]
end
def save(path)
content = render_html(path)
FileUtils.mkdir_p(OUTPUT_DIR)
FileUtils.mkdir_p(File.join(OUTPUT_DIR, path))
File.write(File.join(OUTPUT_DIR, path + ".html"), content)
File.write(File.join(OUTPUT_DIR, path, "index.html"), content)
end
/app/lib/generator.rb
in
block in generate_site
FileUtils.cp_r("./public/assets", OUTPUT_DIR)
puts "Done"
end
def generate_site
puts "Generating site: "
PATHS.each do |path|
save(path)
puts " -> #{path}"
end
puts "Done"
end
def sync_with_s3
puts 'Syncing site files to S3:'
/app/lib/generator.rb
in
each
print "Copying assets folder: "
FileUtils.cp_r("./public/assets", OUTPUT_DIR)
puts "Done"
end
def generate_site
puts "Generating site: "
PATHS.each do |path|
save(path)
puts " -> #{path}"
end
puts "Done"
end
def sync_with_s3
/app/lib/generator.rb
in
generate_site
print "Copying assets folder: "
FileUtils.cp_r("./public/assets", OUTPUT_DIR)
puts "Done"
end
def generate_site
puts "Generating site: "
PATHS.each do |path|
save(path)
puts " -> #{path}"
end
puts "Done"
end
def sync_with_s3
/app/lib/generator.rb
in
build
raise "Unknown action"
end
def build
clean
create_output_dir
copy_assets
generate_site
end
def publish
sync_with_s3
end
def run
/app/lib/generator.rb
in
run
] + Project.all.map {|project| "/projects/#{project.slug}" }
OUTPUT_DIR = "./output"
S3_BUCKET = "test-www.ikmueller.com"
ACTIONS = %w[run clean build publish]
def self.run(action)
return new.send(action) if ACTIONS.include?(action)
raise "Unknown action"
end
def build
clean
create_output_dir
/app/bin/generator
in
<main>
#!/usr/bin/env ruby
require './lib/generator'
Generator.run(ARGV[0])
No GET data.
No POST data.
Variable | Value |
---|---|
PATH_INFO | /project-list |
REQUEST_METHOD | GET |
rack.errors | #<Object:0x00007f1b56539c38> |
rack.input | |
rack.logger | #<Logger:0x00007f1b55bad840 @level=1, @progname=nil, @default_formatter=#<Logger::Formatter:0x00007f1b55bb2188 @datetime_format=nil>, @formatter=nil, @logdev=nil> |
rack.request.cookie_hash | {} |
rack.request.query_hash | {} |
rack.request.query_string | |
sinatra.accept | [#<Sinatra::Request::AcceptEntry:0x00007f1b55ba7030 @entry="*/*", @type="*/*", @params={}, @q=1.0>] |
sinatra.commonlogger | true |
sinatra.error | #<NoMethodError: undefined method `url' for nil:NilClass> |
sinatra.error.params | {} |
sinatra.route | GET /project-list |
You're seeing this error because you have
enabled the show_exceptions
setting.