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`.



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/nrser/errors.rb', line 78

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 = NRSER.erb binding, "    <%= 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.



71
72
73
# File 'lib/nrser/errors.rb', line 71

def errors
  @errors
end