2

I have a specific gem gem installed and I wish to override the following method in the gem's module:

def trace
    exception.backtrace.join("\n")
end

I need to change exception.backtrace.join("\n") to exception.backtrace.join("<br>")

I don't want to create a new fork just for that, so I tried adding this in my initializers:

module ExceptionHandler
    def trace
        exception.backtrace.join("<br>")
    end
end

This doesn't work (obviously).Could someone have a look at the module I linked above and let me know what I'm missing? Thanks!

Ben
  • 2,957
  • 2
  • 27
  • 55

1 Answers1

1

That code is incredibly poorly formatted... Putting it through a formatter like https://www.tutorialspoint.com/online_ruby_formatter.htm reveals that the trace method is on ExceptionHandler::Exception, not ExceptionHandler, so try

class ExceptionHandler::Exception
  def trace
    exception.backtrace.join("<br>")
  end
end

Edit: Since ExceptionHandler::Exception is dynamically defined, you need to prepend your patch instead of reopening the class. The error message you gave implies that something might have changed with the class's constructor. (Possibly from reopening the class..? I can't explain it...) May not make a difference, but try:

module ExceptionHandlerPatch
  def trace
    exception.backtrace.join("<br>")
  end
end

ExceptionHandler::Exception.prepend(ExceptionHandlerPatch)
Glyoko
  • 2,071
  • 1
  • 14
  • 28
  • Does not work for me. Returns "Error during failsafe response: wrong number of arguments (given 1, expected 0)". Fails in app/controllers/exception_handler/exceptions_controller.rb:20:in `initialize' and a few other places – Ben Aug 16 '19 at 02:17
  • Full traceback? – Glyoko Aug 16 '19 at 03:23