Skip to content

Commit 8ac416e

Browse files
Justin Fitzsimmonssteveklabnik
authored andcommitted
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.
1 parent ffaa819 commit 8ac416e

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

lib/resque/failure/redis.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,12 @@ def self.remove(index)
4343
end
4444

4545
def filter_backtrace(backtrace)
46-
index = backtrace.index { |item| item.include?('/lib/resque/job.rb') }
47-
backtrace.first(index.to_i)
46+
index = backtrace.index { |item| item.include?('/lib/resque/job.rb') }.to_i
47+
if index == 0
48+
backtrace
49+
else
50+
backtrace.first(index.to_i)
51+
end
4852
end
4953
end
5054
end

test/resque_failure_redis_test.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,21 @@
2020
@redis_backend.save
2121
Resque::Failure::Redis.all # should not raise an error
2222
end
23+
24+
it "only shows the backtrace for client code" do
25+
backtrace = ["show", "/lib/resque/job.rb", "hide"]
26+
27+
failure = Resque::Failure::Redis.new(nil, nil, nil, nil)
28+
filtered_backtrace = failure.filter_backtrace(backtrace)
29+
30+
assert_equal ["show"], filtered_backtrace
31+
end
32+
it "shows the whole backtrace when the exception happens before client code is reached" do
33+
backtrace = ["everything", "is", "shown"]
34+
35+
failure = Resque::Failure::Redis.new(nil, nil, nil, nil)
36+
filtered_backtrace = failure.filter_backtrace(backtrace)
37+
38+
assert_equal ["everything", "is", "shown"], filtered_backtrace
39+
end
2340
end

0 commit comments

Comments
 (0)