Exception: TCOMethod::AmbiguousSourceError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/tco_method/ambiguous_source_error.rb

Overview

Exception raised when it's not possible to reliably determine the source code of a block.

Constant Summary collapse

MESSAGE =

Default message template.

"Could not determine source of block".freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message = MESSAGE) ⇒ AmbiguousSourceError

Creates a new instance of the exception.

Parameters:

  • message (String) (defaults to: MESSAGE)

    The message to use with the exception.


38
39
40
# File 'lib/tco_method/ambiguous_source_error.rb', line 38

def initialize(message = MESSAGE)
  super
end

Instance Attribute Details

#original_exceptionObject

Returns the exception that this exception was created to wrap if any such exception exists. Used only when this exception is created to wrap another.


11
12
13
# File 'lib/tco_method/ambiguous_source_error.rb', line 11

def original_exception
  @original_exception
end

Class Method Details

.from_proc(block) ⇒ AmbiguousBlockError

Create an exception from a problematic block.

Parameters:

  • block (Proc)

    The block for which the source is ambiguous.

Returns:

  • (AmbiguousBlockError)

    A new exception instance wrapping the given exception.


18
19
20
# File 'lib/tco_method/ambiguous_source_error.rb', line 18

def self.from_proc(block)
  new(MESSAGE + " #{block.inspect}")
end

.wrap(exception) ⇒ AmbiguousBlockError

Wrap another exception with an AmbiguousBlockError. Useful for wrapping errors raised by MethodSource.

Parameters:

  • exception (Exception)

    The exception instance that should be wrapped.

Returns:

  • (AmbiguousBlockError)

    A new exception instance wrapping the given exception.


29
30
31
32
33
# File 'lib/tco_method/ambiguous_source_error.rb', line 29

def self.wrap(exception)
  error = new(exception.message)
  error.original_exception = exception
  error
end