Sha256: 8b9a470ffafeaf8d7eaaab1859da6248d306e6d8493a2138ae6e4432cd376002

Contents?: true

Size: 871 Bytes

Versions: 4

Compression:

Stored size: 871 Bytes

Contents

class Trailblazer::Operation
  NoopHandler = lambda { |*| }

  def self.Rescue(*exceptions, handler: NoopHandler, &block)
    exceptions = [StandardError] unless exceptions.any?
    handler    = Trailblazer::Option(handler)

    # This block is evaluated by {Wrap} which currently expects a binary return type.
    rescue_block = ->(options, flow_options, **circuit_options, &nested_activity) {
      begin
        nested_activity.call
      rescue *exceptions => exception
        # DISCUSS: should we deprecate this signature and rather apply the Task API here?
        handler.call(exception, options, **circuit_options) # FIXME: when there's an error here, it shows the wrong exception!
        false
      end
    }

    Wrap(rescue_block, id: "Rescue(#{rand(100)})", &block)
    # FIXME: name
    # [ step, name: "Rescue:#{block.source_location.last}" ]
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
trailblazer-2.1.0.beta4 lib/trailblazer/operation/rescue.rb
trailblazer-2.1.0.beta3 lib/trailblazer/operation/rescue.rb
trailblazer-2.1.0.beta2 lib/trailblazer/operation/rescue.rb
trailblazer-2.1.0.beta1 lib/trailblazer/operation/rescue.rb