New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stacktraces from middleware swallowed with show exceptions #721

Closed
ahawkins opened this Issue May 31, 2013 · 20 comments

Comments

Projects
None yet
9 participants
@ahawkins

ahawkins commented May 31, 2013

If show_exceptions is set and error is thrown from middleware, the stack trace is swallowed. I'm fairly sure this because of this here: https://github.com/sinatra/sinatra/blob/master/lib/sinatra/showexceptions.rb#L11

Here's an example:

# config.ru
class ErrorTest
  def initialize(app)
  end

  def call(env)
    raise "test!"
  end
end

class Server < Sinatra::Application
   use ErrorTest
end

run Server

Rackup the file. Sinatra will server the 500 page but the trace is missing from the log. I'm not sure if this is a bug or not. It's a weird behavior. If the error is raised inside the sinatra app itself, the stack will appear in the log.

@rkh

This comment has been minimized.

Show comment
Hide comment
@rkh

rkh Jun 7, 2013

Member

I don't think the line you linked has anything to do with it. Will investigate.

Member

rkh commented Jun 7, 2013

I don't think the line you linked has anything to do with it. Will investigate.

@tlemburg

This comment has been minimized.

Show comment
Hide comment
@tlemburg

tlemburg Jul 3, 2013

I can't reproduce this. Throwing an error in the app or the middleware is showing me a stacktrace on both error pages. @ahawkins Could you post a screenshot maybe?

tlemburg commented Jul 3, 2013

I can't reproduce this. Throwing an error in the app or the middleware is showing me a stacktrace on both error pages. @ahawkins Could you post a screenshot maybe?

@patriciomacadden

This comment has been minimized.

Show comment
Hide comment
@patriciomacadden

patriciomacadden Aug 16, 2013

Member

I can confirm the issue. The behavior of Sinatra::ShowExceptions isn't the same as its superclass Rack::ShowExceptions.

You can reproduce the error like this:

class ErrorTest
  def initialize(app)
  end

  def call(env)
    raise "test!"
  end
end

class Server < Sinatra::Application
  use ErrorTest
  disable :show_exceptions
  use Rack::ShowExceptions
end

run Server

You get the error in the console and in the browser (with the Rack::ShowExceptions default style).

Now, with @ahawkins' example, you get the error in the browser only.

I think that the problem is that Sinatra::ShowExceptions is not doing this

Now the question is: Is this the correct behavior for Sinatra::ShowExceptions?

Member

patriciomacadden commented Aug 16, 2013

I can confirm the issue. The behavior of Sinatra::ShowExceptions isn't the same as its superclass Rack::ShowExceptions.

You can reproduce the error like this:

class ErrorTest
  def initialize(app)
  end

  def call(env)
    raise "test!"
  end
end

class Server < Sinatra::Application
  use ErrorTest
  disable :show_exceptions
  use Rack::ShowExceptions
end

run Server

You get the error in the console and in the browser (with the Rack::ShowExceptions default style).

Now, with @ahawkins' example, you get the error in the browser only.

I think that the problem is that Sinatra::ShowExceptions is not doing this

Now the question is: Is this the correct behavior for Sinatra::ShowExceptions?

@yegortimoshenko

This comment has been minimized.

Show comment
Hide comment
@yegortimoshenko

yegortimoshenko Oct 5, 2013

Interestingly, even though there is no stacktrace in console, there is stacktrace in user’s response (in development environment of course):

curl localhost:4567
RuntimeError: test!
    stacktraces.rb:9:in `call'
    /Users/somu/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rack-protection-1.5.0/lib/rack/protection/xss_header.rb:18:in `call'
    /Users/somu/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rack-protection-1.5.0/lib/rack/protection/path_traversal.rb:16:in `call'
    /Users/somu/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rack-protection-1.5.0/lib/rack/protection/json_csrf.rb:18:in `call'
    /Users/somu/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rack-protection-1.5.0/lib/rack/protection/base.rb:49:in `call'
    /Users/somu/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rack-protection-1.5.0/lib/rack/protection/base.rb:49:in `call'
    /Users/somu/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rack-protection-1.5.0/lib/rack/protection/frame_options.rb:31:in `call'
    /Users/somu/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rack-1.5.2/lib/rack/logger.rb:15:in `call'
    /Users/somu/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rack-1.5.2/lib/rack/commonlogger.rb:33:in `call'
    /Users/somu/documents/sinatra/lib/sinatra/base.rb:217:in `call'
    /Users/somu/documents/sinatra/lib/sinatra/base.rb:210:in `call'
    /Users/somu/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rack-1.5.2/lib/rack/head.rb:11:in `call'
    /Users/somu/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rack-1.5.2/lib/rack/methodoverride.rb:21:in `call'
    /Users/somu/documents/sinatra/lib/sinatra/showexceptions.rb:21:in `call'
    /Users/somu/documents/sinatra/lib/sinatra/base.rb:180:in `call'
    /Users/somu/documents/sinatra/lib/sinatra/base.rb:2004:in `call'
    /Users/somu/documents/sinatra/lib/sinatra/base.rb:1469:in `block in call'
    /Users/somu/documents/sinatra/lib/sinatra/base.rb:1778:in `synchronize'
    /Users/somu/documents/sinatra/lib/sinatra/base.rb:1469:in `call'
    /Users/somu/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/thin-1.5.1/lib/thin/connection.rb:81:in `block in pre_process'
    /Users/somu/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/thin-1.5.1/lib/thin/connection.rb:79:in `catch'
    /Users/somu/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/thin-1.5.1/lib/thin/connection.rb:79:in `pre_process'
    /Users/somu/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/eventmachine-1.0.3/lib/eventmachine.rb:1037:in `call'
    /Users/somu/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/eventmachine-1.0.3/lib/eventmachine.rb:1037:in `block in spawn_threadpool'%

yegortimoshenko commented Oct 5, 2013

Interestingly, even though there is no stacktrace in console, there is stacktrace in user’s response (in development environment of course):

curl localhost:4567
RuntimeError: test!
    stacktraces.rb:9:in `call'
    /Users/somu/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rack-protection-1.5.0/lib/rack/protection/xss_header.rb:18:in `call'
    /Users/somu/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rack-protection-1.5.0/lib/rack/protection/path_traversal.rb:16:in `call'
    /Users/somu/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rack-protection-1.5.0/lib/rack/protection/json_csrf.rb:18:in `call'
    /Users/somu/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rack-protection-1.5.0/lib/rack/protection/base.rb:49:in `call'
    /Users/somu/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rack-protection-1.5.0/lib/rack/protection/base.rb:49:in `call'
    /Users/somu/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rack-protection-1.5.0/lib/rack/protection/frame_options.rb:31:in `call'
    /Users/somu/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rack-1.5.2/lib/rack/logger.rb:15:in `call'
    /Users/somu/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rack-1.5.2/lib/rack/commonlogger.rb:33:in `call'
    /Users/somu/documents/sinatra/lib/sinatra/base.rb:217:in `call'
    /Users/somu/documents/sinatra/lib/sinatra/base.rb:210:in `call'
    /Users/somu/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rack-1.5.2/lib/rack/head.rb:11:in `call'
    /Users/somu/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rack-1.5.2/lib/rack/methodoverride.rb:21:in `call'
    /Users/somu/documents/sinatra/lib/sinatra/showexceptions.rb:21:in `call'
    /Users/somu/documents/sinatra/lib/sinatra/base.rb:180:in `call'
    /Users/somu/documents/sinatra/lib/sinatra/base.rb:2004:in `call'
    /Users/somu/documents/sinatra/lib/sinatra/base.rb:1469:in `block in call'
    /Users/somu/documents/sinatra/lib/sinatra/base.rb:1778:in `synchronize'
    /Users/somu/documents/sinatra/lib/sinatra/base.rb:1469:in `call'
    /Users/somu/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/thin-1.5.1/lib/thin/connection.rb:81:in `block in pre_process'
    /Users/somu/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/thin-1.5.1/lib/thin/connection.rb:79:in `catch'
    /Users/somu/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/thin-1.5.1/lib/thin/connection.rb:79:in `pre_process'
    /Users/somu/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/eventmachine-1.0.3/lib/eventmachine.rb:1037:in `call'
    /Users/somu/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/eventmachine-1.0.3/lib/eventmachine.rb:1037:in `block in spawn_threadpool'%

@zzak zzak added the feedback label Feb 13, 2015

@zzak

This comment has been minimized.

Show comment
Hide comment
@zzak

zzak Feb 13, 2015

Member

Marking this ticket for feedback, if no one can reproduce this issue in a reasonable amount of time we should close it.

Member

zzak commented Feb 13, 2015

Marking this ticket for feedback, if no one can reproduce this issue in a reasonable amount of time we should close it.

@kgrz

This comment has been minimized.

Show comment
Hide comment
@kgrz

kgrz Feb 14, 2015

Member

http://cl.ly/image/0A0A163x232Y

I've ran the sample code against master in the first issue comment and ^ that was what showed up in the error page. Backtrace on the console:


0 ❯ curl http://127.0.0.1:9292
RuntimeError: test!
        /Users/kashyap/github_clones/snips/sinatra_721/config.ru:8:in `call'
        /Users/kashyap/github_clones/snips/sinatra_721/vendor/ruby/2.1.0/gems/rack-protection-1.5.3/lib/rack/protection/xss_header.rb:18:in `call'
        /Users/kashyap/github_clones/snips/sinatra_721/vendor/ruby/2.1.0/gems/rack-protection-1.5.3/lib/rack/protection/path_traversal.rb:16:in `call'
        /Users/kashyap/github_clones/snips/sinatra_721/vendor/ruby/2.1.0/gems/rack-protection-1.5.3/lib/rack/protection/json_csrf.rb:18:in `call'
        /Users/kashyap/github_clones/snips/sinatra_721/vendor/ruby/2.1.0/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call'
        /Users/kashyap/github_clones/snips/sinatra_721/vendor/ruby/2.1.0/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call'
        /Users/kashyap/github_clones/snips/sinatra_721/vendor/ruby/2.1.0/gems/rack-protection-1.5.3/lib/rack/protection/frame_options.rb:31:in `call'
        /Users/kashyap/github_clones/snips/sinatra_721/vendor/ruby/2.1.0/gems/rack-1.6.0/lib/rack/logger.rb:15:in `call'
        /Users/kashyap/github_clones/snips/sinatra_721/vendor/ruby/2.1.0/bundler/gems/sinatra-9929353e6c59/lib/sinatra/base.rb:211:in `call'
        /Users/kashyap/github_clones/snips/sinatra_721/vendor/ruby/2.1.0/gems/rack-1.6.0/lib/rack/head.rb:13:in `call'
        /Users/kashyap/github_clones/snips/sinatra_721/vendor/ruby/2.1.0/gems/rack-1.6.0/lib/rack/methodoverride.rb:22:in `call'
        /Users/kashyap/github_clones/snips/sinatra_721/vendor/ruby/2.1.0/bundler/gems/sinatra-9929353e6c59/lib/sinatra/show_exceptions.rb:21:in `call'
        /Users/kashyap/github_clones/snips/sinatra_721/vendor/ruby/2.1.0/bundler/gems/sinatra-9929353e6c59/lib/sinatra/base.rb:181:in `call'
        /Users/kashyap/github_clones/snips/sinatra_721/vendor/ruby/2.1.0/bundler/gems/sinatra-9929353e6c59/lib/sinatra/base.rb:2021:in `call'
        /Users/kashyap/github_clones/snips/sinatra_721/vendor/ruby/2.1.0/bundler/gems/sinatra-9929353e6c59/lib/sinatra/base.rb:1486:in `block in call'
        /Users/kashyap/github_clones/snips/sinatra_721/vendor/ruby/2.1.0/bundler/gems/sinatra-9929353e6c59/lib/sinatra/base.rb:1795:in `synchronize'
        /Users/kashyap/github_clones/snips/sinatra_721/vendor/ruby/2.1.0/bundler/gems/sinatra-9929353e6c59/lib/sinatra/base.rb:1486:in `call'
        /Users/kashyap/github_clones/snips/sinatra_721/vendor/ruby/2.1.0/gems/rack-1.6.0/lib/rack/tempfile_reaper.rb:15:in `call'
        /Users/kashyap/github_clones/snips/sinatra_721/vendor/ruby/2.1.0/gems/rack-1.6.0/lib/rack/lint.rb:49:in `_call'
        /Users/kashyap/github_clones/snips/sinatra_721/vendor/ruby/2.1.0/gems/rack-1.6.0/lib/rack/lint.rb:37:in `call'
        /Users/kashyap/github_clones/snips/sinatra_721/vendor/ruby/2.1.0/gems/rack-1.6.0/lib/rack/showexceptions.rb:24:in `call'
        /Users/kashyap/github_clones/snips/sinatra_721/vendor/ruby/2.1.0/gems/rack-1.6.0/lib/rack/commonlogger.rb:33:in `call'
        /Users/kashyap/github_clones/snips/sinatra_721/vendor/ruby/2.1.0/bundler/gems/sinatra-9929353e6c59/lib/sinatra/base.rb:218:in `call'
        /Users/kashyap/github_clones/snips/sinatra_721/vendor/ruby/2.1.0/gems/rack-1.6.0/lib/rack/chunked.rb:54:in `call'
        /Users/kashyap/github_clones/snips/sinatra_721/vendor/ruby/2.1.0/gems/rack-1.6.0/lib/rack/content_length.rb:15:in `call'
        /Users/kashyap/github_clones/snips/sinatra_721/vendor/ruby/2.1.0/gems/rack-1.6.0/lib/rack/handler/webrick.rb:89:in `service'
        /Users/kashyap/.rubies/ruby-2.1.3/lib/ruby/2.1.0/webrick/httpserver.rb:138:in `service'
        /Users/kashyap/.rubies/ruby-2.1.3/lib/ruby/2.1.0/webrick/httpserver.rb:94:in `run'
        /Users/kashyap/.rubies/ruby-2.1.3/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread'%
Member

kgrz commented Feb 14, 2015

http://cl.ly/image/0A0A163x232Y

I've ran the sample code against master in the first issue comment and ^ that was what showed up in the error page. Backtrace on the console:


0 ❯ curl http://127.0.0.1:9292
RuntimeError: test!
        /Users/kashyap/github_clones/snips/sinatra_721/config.ru:8:in `call'
        /Users/kashyap/github_clones/snips/sinatra_721/vendor/ruby/2.1.0/gems/rack-protection-1.5.3/lib/rack/protection/xss_header.rb:18:in `call'
        /Users/kashyap/github_clones/snips/sinatra_721/vendor/ruby/2.1.0/gems/rack-protection-1.5.3/lib/rack/protection/path_traversal.rb:16:in `call'
        /Users/kashyap/github_clones/snips/sinatra_721/vendor/ruby/2.1.0/gems/rack-protection-1.5.3/lib/rack/protection/json_csrf.rb:18:in `call'
        /Users/kashyap/github_clones/snips/sinatra_721/vendor/ruby/2.1.0/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call'
        /Users/kashyap/github_clones/snips/sinatra_721/vendor/ruby/2.1.0/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call'
        /Users/kashyap/github_clones/snips/sinatra_721/vendor/ruby/2.1.0/gems/rack-protection-1.5.3/lib/rack/protection/frame_options.rb:31:in `call'
        /Users/kashyap/github_clones/snips/sinatra_721/vendor/ruby/2.1.0/gems/rack-1.6.0/lib/rack/logger.rb:15:in `call'
        /Users/kashyap/github_clones/snips/sinatra_721/vendor/ruby/2.1.0/bundler/gems/sinatra-9929353e6c59/lib/sinatra/base.rb:211:in `call'
        /Users/kashyap/github_clones/snips/sinatra_721/vendor/ruby/2.1.0/gems/rack-1.6.0/lib/rack/head.rb:13:in `call'
        /Users/kashyap/github_clones/snips/sinatra_721/vendor/ruby/2.1.0/gems/rack-1.6.0/lib/rack/methodoverride.rb:22:in `call'
        /Users/kashyap/github_clones/snips/sinatra_721/vendor/ruby/2.1.0/bundler/gems/sinatra-9929353e6c59/lib/sinatra/show_exceptions.rb:21:in `call'
        /Users/kashyap/github_clones/snips/sinatra_721/vendor/ruby/2.1.0/bundler/gems/sinatra-9929353e6c59/lib/sinatra/base.rb:181:in `call'
        /Users/kashyap/github_clones/snips/sinatra_721/vendor/ruby/2.1.0/bundler/gems/sinatra-9929353e6c59/lib/sinatra/base.rb:2021:in `call'
        /Users/kashyap/github_clones/snips/sinatra_721/vendor/ruby/2.1.0/bundler/gems/sinatra-9929353e6c59/lib/sinatra/base.rb:1486:in `block in call'
        /Users/kashyap/github_clones/snips/sinatra_721/vendor/ruby/2.1.0/bundler/gems/sinatra-9929353e6c59/lib/sinatra/base.rb:1795:in `synchronize'
        /Users/kashyap/github_clones/snips/sinatra_721/vendor/ruby/2.1.0/bundler/gems/sinatra-9929353e6c59/lib/sinatra/base.rb:1486:in `call'
        /Users/kashyap/github_clones/snips/sinatra_721/vendor/ruby/2.1.0/gems/rack-1.6.0/lib/rack/tempfile_reaper.rb:15:in `call'
        /Users/kashyap/github_clones/snips/sinatra_721/vendor/ruby/2.1.0/gems/rack-1.6.0/lib/rack/lint.rb:49:in `_call'
        /Users/kashyap/github_clones/snips/sinatra_721/vendor/ruby/2.1.0/gems/rack-1.6.0/lib/rack/lint.rb:37:in `call'
        /Users/kashyap/github_clones/snips/sinatra_721/vendor/ruby/2.1.0/gems/rack-1.6.0/lib/rack/showexceptions.rb:24:in `call'
        /Users/kashyap/github_clones/snips/sinatra_721/vendor/ruby/2.1.0/gems/rack-1.6.0/lib/rack/commonlogger.rb:33:in `call'
        /Users/kashyap/github_clones/snips/sinatra_721/vendor/ruby/2.1.0/bundler/gems/sinatra-9929353e6c59/lib/sinatra/base.rb:218:in `call'
        /Users/kashyap/github_clones/snips/sinatra_721/vendor/ruby/2.1.0/gems/rack-1.6.0/lib/rack/chunked.rb:54:in `call'
        /Users/kashyap/github_clones/snips/sinatra_721/vendor/ruby/2.1.0/gems/rack-1.6.0/lib/rack/content_length.rb:15:in `call'
        /Users/kashyap/github_clones/snips/sinatra_721/vendor/ruby/2.1.0/gems/rack-1.6.0/lib/rack/handler/webrick.rb:89:in `service'
        /Users/kashyap/.rubies/ruby-2.1.3/lib/ruby/2.1.0/webrick/httpserver.rb:138:in `service'
        /Users/kashyap/.rubies/ruby-2.1.3/lib/ruby/2.1.0/webrick/httpserver.rb:94:in `run'
        /Users/kashyap/.rubies/ruby-2.1.3/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread'%

@zzak zzak added bug release and removed feedback labels Feb 16, 2015

@zzak

This comment has been minimized.

Show comment
Hide comment
@zzak

zzak Feb 16, 2015

Member

I'd like to resolve this before we do the point release, here's the current patch I'm working on:

diff --git a/lib/sinatra/show_exceptions.rb b/lib/sinatra/show_exceptions.rb
index d7ff54e..2978cbd 100644
--- a/lib/sinatra/show_exceptions.rb
+++ b/lib/sinatra/show_exceptions.rb
@@ -31,6 +31,8 @@ module Sinatra
       end

       env["rack.errors"] = errors
+      env["rack.errors"].puts(exception_string)
+      env["rack.errors"].flush

       # Post 893a2c50 in rack/rack, the #pretty method above, implemented in
       # Rack::ShowExceptions, returns a String instead of an array.

and test:

diff --git a/test/settings_test.rb b/test/settings_test.rb
index 7ec03c6..3ea04df 100644
--- a/test/settings_test.rb
+++ b/test/settings_test.rb
@@ -274,6 +274,28 @@ class SettingsTest < Minitest::Test
     end
   end

+  describe 'show_exceptions with middleware' do
+    class MiddlewareErrorTest
+      def initialize(app); end
+      def call(env)
+        raise StandardError
+      end
+    end
+
+    it 'returns full backtrace for middleware' do
+      klass = Sinatra.new(Sinatra::Application)
+      mock_app(klass) {
+        enable :show_exceptions
+        use MiddlewareErrorTest
+      }
+
+      get '/'
+      assert_equal 500, status
+      assert body.include?("StandardError")
+      assert body.include?("<code>show_exceptions</code> setting")
+    end
+  end
+

Ahh, well as I mentioned before it was raising in the test.. but only because I forgot enable :show_exceptions. I've updated the test to reflect this..

The problem now is this test seems to pass patched and unpatched...

Member

zzak commented Feb 16, 2015

I'd like to resolve this before we do the point release, here's the current patch I'm working on:

diff --git a/lib/sinatra/show_exceptions.rb b/lib/sinatra/show_exceptions.rb
index d7ff54e..2978cbd 100644
--- a/lib/sinatra/show_exceptions.rb
+++ b/lib/sinatra/show_exceptions.rb
@@ -31,6 +31,8 @@ module Sinatra
       end

       env["rack.errors"] = errors
+      env["rack.errors"].puts(exception_string)
+      env["rack.errors"].flush

       # Post 893a2c50 in rack/rack, the #pretty method above, implemented in
       # Rack::ShowExceptions, returns a String instead of an array.

and test:

diff --git a/test/settings_test.rb b/test/settings_test.rb
index 7ec03c6..3ea04df 100644
--- a/test/settings_test.rb
+++ b/test/settings_test.rb
@@ -274,6 +274,28 @@ class SettingsTest < Minitest::Test
     end
   end

+  describe 'show_exceptions with middleware' do
+    class MiddlewareErrorTest
+      def initialize(app); end
+      def call(env)
+        raise StandardError
+      end
+    end
+
+    it 'returns full backtrace for middleware' do
+      klass = Sinatra.new(Sinatra::Application)
+      mock_app(klass) {
+        enable :show_exceptions
+        use MiddlewareErrorTest
+      }
+
+      get '/'
+      assert_equal 500, status
+      assert body.include?("StandardError")
+      assert body.include?("<code>show_exceptions</code> setting")
+    end
+  end
+

Ahh, well as I mentioned before it was raising in the test.. but only because I forgot enable :show_exceptions. I've updated the test to reflect this..

The problem now is this test seems to pass patched and unpatched...

@vipulnsward

This comment has been minimized.

Show comment
Hide comment
@vipulnsward

vipulnsward Feb 21, 2015

Contributor

This behavior is on purpose according to vipulnsward@45e79fc

Using enable :dump_errors should send the exceptions to log. If this looks wrong behavior, I think the fix is to revert vipulnsward@45e79fc instead and let Rack::ShowExceptions take over

Contributor

vipulnsward commented Feb 21, 2015

This behavior is on purpose according to vipulnsward@45e79fc

Using enable :dump_errors should send the exceptions to log. If this looks wrong behavior, I think the fix is to revert vipulnsward@45e79fc instead and let Rack::ShowExceptions take over

@vipulnsward

This comment has been minimized.

Show comment
Hide comment
@vipulnsward
Contributor

vipulnsward commented Feb 21, 2015

@vipulnsward

This comment has been minimized.

Show comment
Hide comment
@vipulnsward

vipulnsward Mar 13, 2015

Contributor

ping @zzak . What are your thoughts about this?
Anything I can help with to get this closed?

Contributor

vipulnsward commented Mar 13, 2015

ping @zzak . What are your thoughts about this?
Anything I can help with to get this closed?

@zzak

This comment has been minimized.

Show comment
Hide comment
@zzak

zzak Mar 14, 2015

Member

@vipulnsward Good find!

Let me see if I can reproduce the expected behavior (now that we know it) using the examples here.
If that is the case, I'm ok to release with the current behavior -- and come back to this for 1.5 or future.

Member

zzak commented Mar 14, 2015

@vipulnsward Good find!

Let me see if I can reproduce the expected behavior (now that we know it) using the examples here.
If that is the case, I'm ok to release with the current behavior -- and come back to this for 1.5 or future.

@vipulnsward

This comment has been minimized.

Show comment
Hide comment
@vipulnsward

vipulnsward Mar 14, 2015

Contributor

Awesome. Lets do this!

On Saturday, March 14, 2015, Zachary Scott notifications@github.com wrote:

@vipulnsward https://github.com/vipulnsward Good find!

Let me see if I can reproduce the expected behavior (now that we know it)
using the examples here.
If that is the case, I'm ok to release with the current behavior -- and
come back to this for 1.5 or future.

Reply to this email directly or view it on GitHub
#721 (comment).

Vipul A.M.
+91-8149-204995

Contributor

vipulnsward commented Mar 14, 2015

Awesome. Lets do this!

On Saturday, March 14, 2015, Zachary Scott notifications@github.com wrote:

@vipulnsward https://github.com/vipulnsward Good find!

Let me see if I can reproduce the expected behavior (now that we know it)
using the examples here.
If that is the case, I'm ok to release with the current behavior -- and
come back to this for 1.5 or future.

Reply to this email directly or view it on GitHub
#721 (comment).

Vipul A.M.
+91-8149-204995

@fj

This comment has been minimized.

Show comment
Hide comment
@fj

fj May 21, 2015

Is this issue still outstanding in either the Rack 1.6.x or 1.5.x series?

fj commented May 21, 2015

Is this issue still outstanding in either the Rack 1.6.x or 1.5.x series?

@zzak

This comment has been minimized.

Show comment
Hide comment
@zzak

zzak May 22, 2015

Member

@fj potentially, are you still able to reproduce it?

Member

zzak commented May 22, 2015

@fj potentially, are you still able to reproduce it?

@fj

This comment has been minimized.

Show comment
Hide comment
@fj

fj May 22, 2015

@zzak When I use:

# foo.ru
require 'sinatra/base'

class ErrorTest
  def initialize(app)
  end

  def call(env)
    raise "test!"
  end
end

class Server < Sinatra::Application
  use ErrorTest
end

run Server

and run rackup foo.ru with Rack 1.6.1 and Sinatra 1.4.6, and then visit localhost:9292, I get an error in the browser but not in the stack trace:

[2015-05-22 17:33:44] INFO  WEBrick 1.3.1
[2015-05-22 17:33:44] INFO  ruby 2.2.2 (2015-04-13) [x86_64-linux]
[2015-05-22 17:33:44] INFO  WEBrick::HTTPServer#start: pid=15922 port=9292
127.0.0.1 - - [22/May/2015:17:33:51 -0400] "GET / HTTP/1.1" 500 89172 0.0224
127.0.0.1 - - [22/May/2015:17:33:51 -0400] "GET /__sinatra__/500.png HTTP/1.1" 500 88768 0.0105

so it seems like the error is still there.

fj commented May 22, 2015

@zzak When I use:

# foo.ru
require 'sinatra/base'

class ErrorTest
  def initialize(app)
  end

  def call(env)
    raise "test!"
  end
end

class Server < Sinatra::Application
  use ErrorTest
end

run Server

and run rackup foo.ru with Rack 1.6.1 and Sinatra 1.4.6, and then visit localhost:9292, I get an error in the browser but not in the stack trace:

[2015-05-22 17:33:44] INFO  WEBrick 1.3.1
[2015-05-22 17:33:44] INFO  ruby 2.2.2 (2015-04-13) [x86_64-linux]
[2015-05-22 17:33:44] INFO  WEBrick::HTTPServer#start: pid=15922 port=9292
127.0.0.1 - - [22/May/2015:17:33:51 -0400] "GET / HTTP/1.1" 500 89172 0.0224
127.0.0.1 - - [22/May/2015:17:33:51 -0400] "GET /__sinatra__/500.png HTTP/1.1" 500 88768 0.0105

so it seems like the error is still there.

@fj

This comment has been minimized.

Show comment
Hide comment
@fj

fj Jun 6, 2015

@zzak Can you confirm whether the above matches your experience?

fj commented Jun 6, 2015

@zzak Can you confirm whether the above matches your experience?

@kgrz

This comment has been minimized.

Show comment
Hide comment
@kgrz

kgrz Jun 9, 2015

Member

Agree with @fj. I've used the code he added and these are my findings: https://gist.github.com/76401485d47d94db33c7

I've tested this with the latest master and can confirm it happens with that as well.

Member

kgrz commented Jun 9, 2015

Agree with @fj. I've used the code he added and these are my findings: https://gist.github.com/76401485d47d94db33c7

I've tested this with the latest master and can confirm it happens with that as well.

@fj

This comment has been minimized.

Show comment
Hide comment
@fj

fj Sep 25, 2015

What needs to be done to resolve this at this point? Having this block releases seems like a big deal.

fj commented Sep 25, 2015

What needs to be done to resolve this at this point? Having this block releases seems like a big deal.

@zzak

This comment has been minimized.

Show comment
Hide comment
@zzak

zzak Jan 31, 2016

Member

This isn't exactly blocking, but would like to resolve any open bugs before we release 2.0.

Member

zzak commented Jan 31, 2016

This isn't exactly blocking, but would like to resolve any open bugs before we release 2.0.

@zzak zzak modified the milestones: 2.0.0, 1.5.0 Jan 31, 2016

@zzak zzak closed this in 36e5b26 May 10, 2016

@fj

This comment has been minimized.

Show comment
Hide comment
@fj

fj May 10, 2016

Thanks for the fix @zzak ❤️.

fj commented May 10, 2016

Thanks for the fix @zzak ❤️.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment