Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Output backtrace when retry_block triggers

Christophe Bliardae61e0968b16
diff --git a/spec/support/rspec_retry.rb b/spec/support/rspec_retry.rb
index e75d4ac6dbf..75249ee87d2 100644
--- a/spec/support/rspec_retry.rb
+++ b/spec/support/rspec_retry.rb
@@ -43,17 +43,19 @@ def retry_block(args: {}, screenshot: false, &block)
log_errors = Proc.new do |exception, try, elapsed_time, next_interval|
max_tries = args[:tries] || (RSpec.current_example.metadata[:retry].to_i + 1)
- exception_source_line = exception.backtrace.find { |line| line.start_with?(Rails.root.to_s) }
+ exception_source_lines = backtrace_up_to_spec_file(exception)
next_try_message = next_interval ? "#{next_interval} seconds until the next try" : "last try"
# use stderr directly to prevent having StructuredWarnings::StandardWarning
# messy and useless output
- $stderr.puts <<~EOS # rubocop:disable Style/StderrPuts
+ $stderr.puts <<~MSG # rubocop:disable Style/StderrPuts
-- rspec-retry #{try}/#{max_tries}--
#{exception.class}: '#{exception.message}'
- occurred on #{exception_source_line}
+ occurred on #{exception_source_lines.first}
+ backtrace:
+ #{exception_source_lines.map { " #{_1}" }.join("\n")}
#{try} tries in #{elapsed_time} seconds, #{next_try_message}.
--
- EOS
+ MSG
if screenshot
begin
@@ -66,3 +68,10 @@ def retry_block(args: {}, screenshot: false, &block)
Retriable.retriable(on_retry: log_errors, **args, &block)
end
+
+def backtrace_up_to_spec_file(exception)
+ exception.backtrace
+ .filter { |line| line.start_with?(Rails.root.to_s) }
+ .take_while { |line| line.exclude?('/bin/rspec:') }
+ .grep_v(%r[/spec/support/shared/with_(mail|direct_uploads)])
+end