From bfb59e0f92271f8ecb60e5b7146c1b6e656938b8 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 8 Oct 2010 12:04:24 -0700 Subject: showexceptions: gracefully handle empty backtraces Some HTTP servers (e.g. Unicorn and Rainbows!) raise certain exceptions without a backtrace[1], so avoid triggering our own NoMethodError exception because of this. [1] - http://git.bogomips.org/cgit/unicorn.git/commit/?id=e4256da292f9626d7dfca60e08f65651a0a9139a --- lib/rack/showexceptions.rb | 8 +++++++- test/spec_showexceptions.rb | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/rack/showexceptions.rb b/lib/rack/showexceptions.rb index 697bc41f..26ff9239 100644 --- a/lib/rack/showexceptions.rb +++ b/lib/rack/showexceptions.rb @@ -195,7 +195,13 @@ TEMPLATE = <<'HTML'

<%=h exception.message %>

- + diff --git a/test/spec_showexceptions.rb b/test/spec_showexceptions.rb index 82ac9184..908f7b73 100644 --- a/test/spec_showexceptions.rb +++ b/test/spec_showexceptions.rb @@ -20,4 +20,24 @@ describe Rack::ShowExceptions do res.should =~ /RuntimeError/ res.should =~ /ShowExceptions/ end + + it "handles exceptions without a backtrace" do + res = nil + + req = Rack::MockRequest.new( + Rack::ShowExceptions.new( + lambda{|env| raise RuntimeError, "", [] } + )) + + lambda{ + res = req.get("/") + }.should.not.raise + + res.should.be.a.server_error + res.status.should.equal 500 + + res.should =~ /RuntimeError/ + res.should =~ /ShowExceptions/ + res.should =~ /unknown location/ + end end -- cgit v1.2.3-24-ge0c7
Ruby<%=h frames.first.filename %>: in <%=h frames.first.function %>, line <%=h frames.first.lineno %> +<% if first = frames.first %> + <%=h first.filename %>: in <%=h first.function %>, line <%=h frames.first.lineno %> +<% else %> + unknown location +<% end %> +
Web <%=h req.request_method %> <%=h(req.host + path)%>