1
0
Fork 0
mirror of https://github.com/sinatra/sinatra synced 2023-03-27 23:18:01 -04:00

Dump backtrace to rack.errors on unhandled exception

Also added a dump_errors option so that this can be disabled
when necessary.
This commit is contained in:
Ryan Tomayko 2009-01-09 02:28:08 -08:00
parent 49c60151bf
commit b5faa571f5
3 changed files with 24 additions and 0 deletions

View file

@ -1,5 +1,9 @@
= 0.9.0 (unreleased)
* New "dump_errors" option controls whether the backtrace is dumped to
rack.errors when an exception is raised from a route. The option is
enabled by default for top-level apps.
* New ":provides" route condition takes an array of mime types and
matches only when an Accept request header is present with a
corresponding type. [cypher]

View file

@ -411,6 +411,12 @@ module Sinatra
invoke handler unless handler.nil?
rescue ::Exception => boom
@env['sinatra.error'] = boom
if options.dump_errors?
msg = ["#{boom.class} - #{boom.message}:", *boom.backtrace].join("\n ")
@env['rack.errors'] << msg
end
raise boom if options.raise_errors?
@response.status = 500
invoke errmap[boom.class] || errmap[Exception]
@ -660,6 +666,7 @@ module Sinatra
end
set :raise_errors, true
set :dump_errors, false
set :sessions, false
set :logging, false
set :methodoverride, false
@ -753,6 +760,7 @@ module Sinatra
class Default < Base
set :raise_errors, false
set :dump_errors, true
set :sessions, false
set :logging, true
set :methodoverride, true

View file

@ -50,6 +50,18 @@ describe 'Exception Mappings' do
body.should.equal 'looks good'
end
it 'dumps errors to rack.errors when dump_errors is enabled' do
mock_app {
set :raise_errors, false
set :dump_errors, true
get('/') { raise FooError, 'BOOM!' }
}
get '/'
status.should.equal 500
@response.errors.should.match(/FooError - BOOM!:/)
end
it "raises without calling the handler when the raise_errors options is set" do
mock_app {
set :raise_errors, true