class FilePipeline::Errors::FailedModificationError

Error class for exceptions that are raised when a a FileOperation in a Pipeline returns failure.

Attributes

info[R]

The file opration that caused the error.

Public Class Methods

new(msg = nil, info: nil, file: nil) click to toggle source

Returns a new instance.

Arguments
  • msg - error message for the exception. If none provided, the instance will be initialized with the default_message.

Options
Calls superclass method
# File lib/file_pipeline/errors/failed_modification_error.rb, line 22
def initialize(msg = nil, info: nil, file: nil)
  @file = file
  @info = info
  msg ||= default_message
  super msg
end

Public Instance Methods

original_backtrace() click to toggle source

Returns the backtrace of the error that caused the exception.

# File lib/file_pipeline/errors/failed_modification_error.rb, line 30
def original_backtrace
  original_error&.backtrace&.join("\n")
end
original_error() click to toggle source

Returns the error that caused the exception.

# File lib/file_pipeline/errors/failed_modification_error.rb, line 35
def original_error
  @info.log.find { |item| item.is_a? Exception }
end

Private Instance Methods

append_backtrace(str) click to toggle source

Appends the backtrace of the error that caused the exception to the default_message.

# File lib/file_pipeline/errors/failed_modification_error.rb, line 43
def append_backtrace(str)
  return "#{str}\n" unless original_backtrace

  "#{str} Backtrace:\n#{original_backtrace}"
end
append_error(str) click to toggle source

Appends the message of the error that caused the exception to the default_message.

# File lib/file_pipeline/errors/failed_modification_error.rb, line 51
def append_error(str)
  return str unless original_error

  str += "\nException raised by the operation:"\
    " #{original_error.inspect}."
  append_backtrace str
end
default_message() click to toggle source

Returns a String with the message for self.

# File lib/file_pipeline/errors/failed_modification_error.rb, line 60
def default_message
  if info.respond_to?(:operation) && info.respond_to?(:log)
    msg = "#{info.operation&.name} with options"\
      " #{info.operation&.options} failed on #{@file}."
    append_error msg
  else
    'Operation failed'
  end
end