I’m trying to figure out how to implement error handling with dry-monads without creating leaky abstractions. Consider a 3rd party dependency that is implemented using monads:
class UseCase
include Dry::Monads::Do.for(:call)
include Dry::Monads::Result::Mixin
include Inject['dependency']
def call
# if this fails, it leaks implementation details about underlying dependencies error domain,
# possibly even implementations details that are in layers below dependency
foo = yield dependency.call
Success(foo.value)
end
end
if you were implementing this with exceptions and try/catch, you would catch the underlying dependencies exception and raise a new exception in order to prevent the underlying exception from leaking to the caller.
is there a simple pattern for doing this sort of error translation with dry-monads with or without do notation?