sinatra: Error block not working
I have the following Sinatra app and I am testing the error block but it doesnt seem to be working i.e I do not see anything in the std output.
require 'sinatra'
error do
puts "----> Failed"
$stdout.print "----> Failed"
end
get "/error" do
raise "OMG"
end
I am using sinatra (1.3.3)
About this issue
- Original URL
- State: closed
- Created 14 years ago
- Comments: 19 (14 by maintainers)
The default behavior should be to use the custom error block in both production and in development. I can understand the rationale of not wanting to show stack traces in production, but this should be done without affecting the custom error block. IMHO This bothers me as well…
@JonRowe I understand that point of view. I’m not sure to agree with “Your use case isn’t the expected behaviour.” though.
I can imagine that most people would interpret sinatra’s error blocks as a standard try/catch mechanism, mostly because there are very few other exception mechanisms available. Imagine what you would think about ruby changing its behavior wrt rescue clauses according to an environment variable. Wouldn’t you think it to be (very) odd?? In web, rack/sinatra is your dev platform and it’s recue clauses are odd by default 😉
Hi, I looked into this for you with the aim to writing a patch, the issue is that in
:developmentmoderaise_errorsis set so that Sinatra can do the magic stack trace page, if you want to test the behaviour of your handlers you need to setraise_errorsto befalse. See the mapped error tests for more information.Try with:
ruby test_error.rb -env production