Exception: NRSER::MultipleErrors

Inherits:
StandardError
  • Object
show all
Defined in:
lib/nrser/errors.rb

Overview

A wrapper error around a list of other errors.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(errors, headline: nil) ⇒ MultipleErrors

Instantiate a new ‘MultipleErrors`.



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/nrser/errors.rb', line 42

def initialize errors, headline: nil
  @errors = errors
  
  if headline.nil?
    class_counts = NRSER.count_by( errors, &:class ).
      map { |klass, count| "#{ klass } (#{ count })" }.
      join( ', ' )
    
    headline = "#{ errors.count } error(s) occurred - #{ class_counts }"
  end
  
  message = binding.erb "    <%= headline %>\n    \n    <% errors.each_with_index do |error, index| %>\n    <%= (index.succ.to_s + \".\").ljust( 3 ) %> <%= error.message %> (<%= error.class %>):\n        <%= error.backtrace.join( $/ ) %>\n    <% end %>\n    \n  END\n  \n  super message\nend\n"

Instance Attribute Details

#errorsArray<Exception> (readonly)

The individual errors that occurred.

Returns:



35
36
37
# File 'lib/nrser/errors.rb', line 35

def errors
  @errors
end