lib/trailblazer/operation/rescue.rb in trailblazer-2.0.7 vs lib/trailblazer/operation/rescue.rb in trailblazer-2.1.0.beta1
- old
+ new
@@ -1,21 +1,24 @@
class Trailblazer::Operation
- def self.Rescue(*exceptions, handler: lambda { |*| }, &block)
+ NoopHandler = lambda { |*| }
+
+ def self.Rescue(*exceptions, handler: NoopHandler, &block)
exceptions = [StandardError] unless exceptions.any?
- handler = Option.(handler)
+ handler = Trailblazer::Option(handler)
- rescue_block = ->(options, operation, *, &nested_pipe) {
+ # This block is evaluated by {Wrap} which currently expects a binary return type.
+ rescue_block = ->(options, flow_options, **circuit_options, &nested_activity) {
begin
- res = nested_pipe.call
- res.first == ::Pipetree::Railway::Right # FIXME.
+ nested_activity.call
rescue *exceptions => exception
- handler.call(operation, exception, options)
+ # 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
}
- step, _ = Wrap(rescue_block, &block)
-
- [ step, name: "Rescue:#{block.source_location.last}" ]
+ Wrap(rescue_block, id: "Rescue(#{rand(100)})", &block)
+ # FIXME: name
+ # [ step, name: "Rescue:#{block.source_location.last}" ]
end
end