Skip to content

Commit

Permalink
Merge pull request #36 from B-CDD/chore/examples-backtrace-cleaner
Browse files Browse the repository at this point in the history
Improve backtrace cleaner (examples)
  • Loading branch information
serradura authored Mar 15, 2024
2 parents a3a650f + 2d7c9b1 commit b1b334b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ def before_interruption(exception:, transitions:)

dir = "#{FileUtils.pwd[1..]}/"

listener_filename = File.basename(__FILE__).chomp('.rb')

cb = bc.clean(exception.backtrace)
cb.each { _1.sub!(dir, '') }
cb.reject! { _1.match?(/block \(\d levels?\) in|in `block in|internal:kernel/) }
cb.reject! { _1.match?(/block \(\d levels?\) in|in `block in|internal:kernel|#{listener_filename}/) }

puts "\nException:\n #{exception.message} (#{exception.class})\n\nBacktrace:\n #{cb.join("\n ")}"
end
Expand Down
10 changes: 8 additions & 2 deletions examples/single_listener/lib/single_transitions_listener.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,14 @@ def before_interruption(exception:, transitions:)
bc.add_silencer { |line| /lib\/bcdd\/result/.match?(line) }
bc.add_silencer { |line| line.include?(RUBY_VERSION) }

backtrace = bc.clean(exception.backtrace)
dir = "#{FileUtils.pwd[1..]}/"

puts "\nException: #{exception.message} (#{exception.class}); Backtrace: #{backtrace.join(", ")}"
listener_filename = File.basename(__FILE__).chomp('.rb')

cb = bc.clean(exception.backtrace)
cb.each { _1.sub!(dir, '') }
cb.reject! { _1.match?(/block \(\d levels?\) in|in `block in|internal:kernel|#{listener_filename}/) }

puts "\nException:\n #{exception.message} (#{exception.class})\n\nBacktrace:\n #{cb.join("\n ")}"
end
end

0 comments on commit b1b334b

Please sign in to comment.