dry-effect and exceptions (truncated stacktrace)

Hi,

I am using a dry-effect in my controller (hanami) to provide a Reader which is used to provide scoping information to the repositories e.g. organisation_id.

I have noticed that when an exception is thrown, my stacktrace has stack information all the way up to the point I use the dry-effect which prevents me from seeing which controller the error originated from.

I can solve this by wrapping the call method at a rack level using a dry-effect Reader which does not provide anything but just ensuring the dry-effect reader happening further up the stack is wrapped.

e.g.

require 'dry/effects'

class RootDryEffect
  include Dry::Effects::Handler.State(:root)
  def initialize(app)
    @app = app
  end

  def call(env)
    _, response = with_root({}) do
      @app.call(env)
    end
    response
  end
end

and then calling it with:

middleware.use RootDryEffect

Is there a better way to achieve this? / downsides to this approach?

Sorry for the late response. I don’t think that there’s a better way of doing this atm. Personally, I have effect handlers high enough not to face this issue. That said, it seems to be a good idea to glue stack traces. I’ll give it a spin.