* [PATCH] showexceptions: gracefully handle empty backtraces
@ 2010-10-08 20:58 Eric Wong
2010-10-10 20:45 ` James Tucker
0 siblings, 1 reply; 2+ messages in thread
From: Eric Wong @ 2010-10-08 20:58 UTC (permalink / raw)
To: rack-devel
Also pushed out to the "showexceptions" branch of
git://git.bogomips.org/rack.git
http://git.bogomips.org/cgit/rack.git/commit/?id=bfb59e0f92271f8ecb60e5b7146c1b6e656938b8
From bfb59e0f92271f8ecb60e5b7146c1b6e656938b8 Mon Sep 17 00:00:00 2001
From: Eric Wong <normalperson@yhbt.net>
Date: Fri, 8 Oct 2010 12:04:24 -0700
Subject: [PATCH] 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 deletions(-)
diff --git a/lib/rack/showexceptions.rb b/lib/rack/showexceptions.rb
index 697bc41..26ff923 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 82ac918..908f7b7 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
--
Eric Wong
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] showexceptions: gracefully handle empty backtraces
2010-10-08 20:58 [PATCH] showexceptions: gracefully handle empty backtraces Eric Wong
@ 2010-10-10 20:45 ` James Tucker
0 siblings, 0 replies; 2+ messages in thread
From: James Tucker @ 2010-10-10 20:45 UTC (permalink / raw)
To: rack-devel
Merged, thanks Eric!
On 8 Oct 2010, at 17:58, Eric Wong wrote:
> Also pushed out to the "showexceptions" branch of
> git://git.bogomips.org/rack.git
>
> http://git.bogomips.org/cgit/rack.git/commit/?id=bfb59e0f92271f8ecb60e5b7146c1b6e656938b8
>
> From bfb59e0f92271f8ecb60e5b7146c1b6e656938b8 Mon Sep 17 00:00:00 2001
> From: Eric Wong <normalperson@yhbt.net>
> Date: Fri, 8 Oct 2010 12:04:24 -0700
> Subject: [PATCH] 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 deletions(-)
>
> diff --git a/lib/rack/showexceptions.rb b/lib/rack/showexceptions.rb
> index 697bc41..26ff923 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 82ac918..908f7b7 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
> --
> Eric Wong
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2010-10-10 20:45 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-10-08 20:58 [PATCH] showexceptions: gracefully handle empty backtraces Eric Wong
2010-10-10 20:45 ` James Tucker
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).