Exception: Oni::WrappedError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/oni/wrapped_error.rb

Overview

Error class that can be used to wrap existing errors and attach extra data to them. This class is primarily intended to be used within workers to attach the input to the error.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message = nil, options = {}) ⇒ WrappedError

Returns a new instance of WrappedError.

Parameters:

  • message (String) (defaults to: nil)
  • options (Hash) (defaults to: {})


35
36
37
38
39
40
41
# File 'lib/oni/wrapped_error.rb', line 35

def initialize(message = nil, options = {})
  super(message)

  options.each do |key, value|
    instance_variable_set("@#{key}", value) if respond_to?(key)
  end
end

Instance Attribute Details

#original_errorStandardError (readonly)

Returns:

  • (StandardError)


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/oni/wrapped_error.rb', line 13

class WrappedError < StandardError
  attr_reader :original_error, :parameters

  ##
  # Wraps an existing error.
  #
  # @param [StandardError] error
  # @param [Mixed] parameters
  # @return [Oni::WrappedError]
  #
  def self.from(error, parameters = nil)
    return new(
      error.message,
      :original_error => error,
      :parameters     => parameters
    )
  end

  ##
  # @param [String] message
  # @param [Hash] options
  #
  def initialize(message = nil, options = {})
    super(message)

    options.each do |key, value|
      instance_variable_set("@#{key}", value) if respond_to?(key)
    end
  end
end

#parametersMixed (readonly)

Returns:

  • (Mixed)


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/oni/wrapped_error.rb', line 13

class WrappedError < StandardError
  attr_reader :original_error, :parameters

  ##
  # Wraps an existing error.
  #
  # @param [StandardError] error
  # @param [Mixed] parameters
  # @return [Oni::WrappedError]
  #
  def self.from(error, parameters = nil)
    return new(
      error.message,
      :original_error => error,
      :parameters     => parameters
    )
  end

  ##
  # @param [String] message
  # @param [Hash] options
  #
  def initialize(message = nil, options = {})
    super(message)

    options.each do |key, value|
      instance_variable_set("@#{key}", value) if respond_to?(key)
    end
  end
end

Class Method Details

.from(error, parameters = nil) ⇒ Oni::WrappedError

Wraps an existing error.

Parameters:

  • error (StandardError)
  • parameters (Mixed) (defaults to: nil)

Returns:



23
24
25
26
27
28
29
# File 'lib/oni/wrapped_error.rb', line 23

def self.from(error, parameters = nil)
  return new(
    error.message,
    :original_error => error,
    :parameters     => parameters
  )
end