Sha256: 77a124387894f0c6f618d9e5d6b5b215fe2dee356a18cee7cc29236620e8172c

Contents?: true

Size: 1.14 KB

Versions: 4

Compression:

Stored size: 1.14 KB

Contents

module Interactor
  # Internal: Error raised during Interactor::Context failure. The error stores
  # a copy of the failed context for debugging purposes.
  class Failure < StandardError
    # Internal: Gets the Interactor::Context of the Interactor::Failure
    # instance.
    attr_reader :context

    # Internal: Initialize an Interactor::Failure.
    #
    # context - An Interactor::Context to be stored within the
    #           Interactor::Failure instance. (default: nil)
    #
    # Examples
    #
    #   Interactor::Failure.new
    #   # => #<Interactor::Failure: Interactor::Failure>
    #
    #   context = Interactor::Context.new(foo: "bar")
    #   # => #<Interactor::Context foo="bar">
    #   Interactor::Failure.new(context)
    #   # => #<Interactor::Failure: #<Interactor::Context foo="bar">>
    #
    #   raise Interactor::Failure, context
    #   # => Interactor::Failure: #<Interactor::Context foo="bar">
    def initialize(context = nil)
      @context = context
      super
    end

    def cause_stack
      causes = [context.error_cause]
      causes << causes.last.cause while causes.last&.cause

      causes.compact
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
interactor_with_steroids-1.5.1 lib/interactor/error.rb
interactor_with_steroids-1.5.0 lib/interactor/error.rb
interactor_with_steroids-1.4.0 lib/interactor/error.rb
interactor_with_steroids-1.3.0 lib/interactor/error.rb