Skip to content

Commit

Permalink
Added error rendering to the web_server.
Browse files Browse the repository at this point in the history
  • Loading branch information
dbalatero committed Jun 10, 2009
1 parent 479e699 commit 8969bf3
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 21 deletions.
42 changes: 22 additions & 20 deletions lib/queue_stick/views/index.erb
Original file line number Diff line number Diff line change
Expand Up @@ -68,33 +68,35 @@
<% end %>
</div>
<div class="yui-u">
<h1>Errors (3)</h1>
<h1>Errors (<%= @errors.count %>)</h1>
<ul>
<li class="error" id="error-1">
<span class="klass">ArgumentError</span> |
<span class="time">5 minutes ago</span> |
<span class="desc">Wrong number of arguments (0 for 1...</span>
<% @errors.each_with_index do |error, id| %>
<li class="error" id="error-<%= id %>">
<span class="klass"><%= error.exceptions[0].class.to_s %></span> |
<span class="time"><%= time_ago_or_time_stamp(error.timestamp) %></span> |
<span class="desc"><%= truncate(error.exceptions[0].message, 20) %></span>
</li>
<li class="error-detail" id="error-1-detail">
<li class="error-detail" id="error-<%= id %>-detail">
<ul>
<li><strong>Message ID:</strong> 94939002</li>
<li><strong>Timestamp:</strong> June 14, 2009</li>
<li><strong>Message ID:</strong> <%= error.message.id %></li>
<li><strong>Timestamp:</strong> <%= error.timestamp %></li>
</ul>
<pre>
ArgumentError: ArgumentError
from (irb):1
Queue message body:
----------------------
<%= error.message.body %>

----------------------
Exceptions:
----------------------
<% error.exceptions.each do |exception| %>
<%= exception.message %>
<%= exception.backtrace.join("\n") %>
----------------------
<% end %>
</pre>
</li>
<li class="error" id="error-2">
<span class="klass">ArgumentError</span> |
<span class="time">7 minutes ago</span> |
<span class="desc">Wrong number of arguments (0 for 1...</span>
</li>
<li class="error" id="error-3">
<span class="klass">ArgumentError</span> |
<span class="time">9 minutes ago</span> |
<span class="desc">Wrong number of arguments (0 for 2...</span>
</li>
<% end %>
</ul>
</div>
</div>
Expand Down
7 changes: 7 additions & 0 deletions lib/queue_stick/web_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ class WebServer < Sinatra::Application
end
end

# Pull out the error messages per thread.
@errors = []
@workers.each do |worker|
@errors += worker.errors
end
@errors.sort! { |a, b| a.timestamp <=> b.timestamp }.reverse!

erb :index
end

Expand Down
27 changes: 26 additions & 1 deletion spec/queue_stick/web_server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,25 @@ def app

# half-life DM, son!
runner.should_receive(:port).and_return(27015)

workers = [QueueStick::MockWorker.new,
QueueStick::MockWorker.new,
QueueStick::MockWorker.new]

message = QueueStick::MockMessage.new("{ 'my_json':'json value' }")
worker_error = QueueStick::WorkerError.new(message)

# Kinda ghetto... but I want a stack trace.
begin
raise ArgumentError, "You passed in the wrong thing!"
rescue ArgumentError => error
worker_error.exceptions << error
end

workers[0].should_receive(:errors).and_return([worker_error])
workers[1].should_receive(:errors).and_return([])
workers[2].should_receive(:errors).and_return([])

runner.should_receive(:workers).and_return(workers)

app.set :queue_runner, runner
Expand Down Expand Up @@ -58,5 +73,15 @@ def app
last_response.body.should =~ /<h\d>Messages processed<\/h\d>/
end
end

describe "errors" do
it "should have the total error count" do
last_response.body.should =~ /<h1>Errors \(1\)<\/h1>/
end

it "should have the single error on the page" do
last_response.body.should =~ /<span class="klass">ArgumentError/
end
end
end
end

0 comments on commit 8969bf3

Please sign in to comment.