Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Only filter backtrace for client exceptions

The backtrace filtering will now show something when the exception
originates prior to resque/job.rb. This can happen when there is a
bug in resque, or when a hook manages to crash before job has a
chance to start up. This allows users a chance to debug instead of
just giving them an exception message with no backtrace at all.
  • Loading branch information...
commit 99c7c786328c57252f4606a65dd94619882d59d8 1 parent 47bd9a0
@Fitzsimmons Fitzsimmons authored steveklabnik committed
Showing with 23 additions and 2 deletions.
  1. +6 −2 lib/resque/failure/redis.rb
  2. +17 −0 test/resque_failure_redis_test.rb
View
8 lib/resque/failure/redis.rb
@@ -43,8 +43,12 @@ def self.remove(index)
end
def filter_backtrace(backtrace)
- index = backtrace.index { |item| item.include?('/lib/resque/job.rb') }
- backtrace.first(index.to_i)
+ index = backtrace.index { |item| item.include?('/lib/resque/job.rb') }.to_i
+ if index == 0
+ backtrace
+ else
+ backtrace.first(index.to_i)
+ end
end
end
end
View
17 test/resque_failure_redis_test.rb
@@ -20,4 +20,21 @@
@redis_backend.save
Resque::Failure::Redis.all # should not raise an error
end
+
+ it "only shows the backtrace for client code" do
+ backtrace = ["show", "/lib/resque/job.rb", "hide"]
+
+ failure = Resque::Failure::Redis.new(nil, nil, nil, nil)
+ filtered_backtrace = failure.filter_backtrace(backtrace)
+
+ assert_equal ["show"], filtered_backtrace
+ end
+ it "shows the whole backtrace when the exception happens before client code is reached" do
+ backtrace = ["everything", "is", "shown"]
+
+ failure = Resque::Failure::Redis.new(nil, nil, nil, nil)
+ filtered_backtrace = failure.filter_backtrace(backtrace)
+
+ assert_equal ["everything", "is", "shown"], filtered_backtrace
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.