Method: ShopifyCLI::Result::Failure#rescue

Defined in:
lib/shopify_cli/result.rb

#rescue(&block) ⇒ Object

can be used to recover from a failure or produce a new failure with a different error.

Failure
  .new("Something went wrong")
  .rescue { |msg| [msg, "but we fixed it!"].join(" "") }
  .tap do |result|
     result.success? # => true
     result.value # => "Something went wrong but we fixed it!"
  end

‘rescue` is opinionated when it comes to the return value of the block. If the return value is an `Exception` – either one that was raised or an instance of a subclass of `Exception` – a `Failure` is returned. Any other value results in a `Success` unless the value has been explicitly wrapped in a `Failure`:

Failure
  .new(RuntimeError.new)
  .rescue { "All good! "}
  .success? # => true

Failure
  .new(RuntimeError.new)
  .rescue { Failure.new("Still broken!") }
  .success? # => false


322
323
324
# File 'lib/shopify_cli/result.rb', line 322

def rescue(&block)
  Result.wrap(&block).call(@error)
end