summary refs log tree commit
diff options
context:
space:
mode:
-rw-r--r--lib/rack/showexceptions.rb8
-rw-r--r--test/spec_showexceptions.rb20
2 files changed, 27 insertions, 1 deletions
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'
   <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 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