Module: Backup::NestedExceptions
- Included in:
- Error, FatalError
- Defined in:
- lib/backup/errors.rb
Overview
Provides cascading errors with formatted messages. See the specs for details.
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.included(klass) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/backup/errors.rb', line 5 def self.included(klass) klass.extend Module.new { def wrap(wrapped_exception, msg = nil) new(msg, wrapped_exception) end } end |
Instance Method Details
#exception(obj = nil) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/backup/errors.rb', line 31 def exception(obj = nil) return self if obj.nil? || equal?(obj) ex = self.class.new(obj, @wrapped_exception) ex.set_backtrace(backtrace) unless ex.backtrace ex end |
#initialize(obj = nil, wrapped_exception = nil) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/backup/errors.rb', line 13 def initialize(obj = nil, wrapped_exception = nil) @wrapped_exception = wrapped_exception msg = (obj.respond_to?(:to_str) ? obj.to_str : obj.to_s) .gsub(/^ */, " ").strip msg = clean_name(self.class.name) + (msg.empty? ? "" : ": #{msg}") if wrapped_exception msg << "\n--- Wrapped Exception ---\n" class_name = clean_name(wrapped_exception.class.name) msg << class_name + ": " unless wrapped_exception..start_with? class_name msg << wrapped_exception. end super(msg) set_backtrace(wrapped_exception.backtrace) if wrapped_exception end |