summary refs log tree commit
diff options
context:
space:
mode:
authorraggi <jftucker@gmail.com>2010-10-10 17:42:22 -0300
committerraggi <jftucker@gmail.com>2010-10-10 17:42:22 -0300
commit733e548d8c4487e8cb143cba611a825fe6853e76 (patch)
treec984c0ad087913826615205428a07996d4807026
parent2f68598a90149678fa5bf32f40d32b9abda5b9f5 (diff)
downloadrack-733e548d8c4487e8cb143cba611a825fe6853e76.tar.gz
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

Conflicts:

	test/spec_showexceptions.rb

Signed-off-by: raggi <jftucker@gmail.com>
-rw-r--r--lib/rack/showexceptions.rb8
-rw-r--r--test/spec_showexceptions.rb21
2 files changed, 28 insertions, 1 deletions
diff --git a/lib/rack/showexceptions.rb b/lib/rack/showexceptions.rb
index f0a5d564..c85f5223 100644
--- a/lib/rack/showexceptions.rb
+++ b/lib/rack/showexceptions.rb
@@ -213,7 +213,13 @@ TEMPLATE = <<'HTML'
   <h2><%=h exception.message %></h2>
   <table><tr>
     <th>Ruby</th>
-    <td><code><%=h frames.first.filename %></code>: in <code><%=h frames.first.function %></code>, line <%=h frames.first.lineno %></td>
+    <td>
+<% if first = frames.first %>
+      <code><%=h first.filename %></code>: in <code><%=h first.function %></code>, line <%=h frames.first.lineno %>
+<% else %>
+      unknown location
+<% end %>
+    </td>
   </tr><tr>
     <th>Web</th>
     <td><code><%=h req.request_method %> <%=h(req.host + path)%></code></td>
diff --git a/test/spec_showexceptions.rb b/test/spec_showexceptions.rb
index 039c7f0f..5bfc9529 100644
--- a/test/spec_showexceptions.rb
+++ b/test/spec_showexceptions.rb
@@ -63,4 +63,25 @@ describe Rack::ShowExceptions do
     res.body.should.include "It was never supposed to work"
     res.body.should.include Rack::Utils.escape_html(__FILE__)
   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