You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
484 B

  1. # frozen_string_literal: true
  2. class SidekiqErrorHandler
  3. BACKTRACE_LIMIT = 3
  4. def call(*)
  5. yield
  6. rescue Mastodon::HostValidationError
  7. # Do not retry
  8. rescue => e
  9. limit_backtrace_and_raise(e)
  10. ensure
  11. socket = Thread.current[:statsd_socket]
  12. socket&.close
  13. Thread.current[:statsd_socket] = nil
  14. end
  15. private
  16. def limit_backtrace_and_raise(exception)
  17. exception.set_backtrace(exception.backtrace.first(BACKTRACE_LIMIT))
  18. raise exception
  19. end
  20. end