Exception: Krikri::Mapping::Error

Inherits:
RuntimeError
  • Object
show all
Defined in:
lib/krikri/mapping.rb

Overview

An error class for exceptions thrown during ‘Krikri::Mapping` processes.

Collects the full set of errors encountered when mapping a given record, along with the property names that were being processed when throwing the error.

Examples:

collecting exceptions and reraising

err = Krikri::Mapping::Error.new(record)
err.add(:title, exception)
raise err

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(record) ⇒ Error

Returns a new instance of Error.

Parameters:



84
85
86
87
# File 'lib/krikri/mapping.rb', line 84

def initialize(record)
  @original_record = record
  @errors = {}
end

Instance Attribute Details

#errorsObject

Returns the value of attribute errors.



80
81
82
# File 'lib/krikri/mapping.rb', line 80

def errors
  @errors
end

#original_recordObject

Returns the value of attribute original_record.



80
81
82
# File 'lib/krikri/mapping.rb', line 80

def original_record
  @original_record
end

Instance Method Details

#add(property, parent_error) ⇒ Object

Parameters:

  • property (Symbol)

    the name of the property for the error

  • parent_error (Exception)

    the error to add



92
93
94
# File 'lib/krikri/mapping.rb', line 92

def add(property, parent_error)
  errors[property] = parent_error
end

#messageString

Returns a message describing the full error set.

Returns:

  • (String)

    a message describing the full error set



104
105
106
107
108
109
110
111
112
# File 'lib/krikri/mapping.rb', line 104

def message
  msg = "Error processing mapping for #{original_record.local_name}\n"
  errors.each do |property, error|
    msg << "Failed on property #{property}:\n"
    msg << "\t#{error.message}\n\t#{error.backtrace.join("\n\t")}"
  end

  msg
end

#propertiesArray<Symbol>

Returns the property names that caused errors.

Returns:

  • (Array<Symbol>)

    the property names that caused errors



98
99
100
# File 'lib/krikri/mapping.rb', line 98

def properties
  errors.keys
end