class Demiurge::Errors::Exception

Demiurge::Errors::Exception is the parent class of all Demiurge-specific Exceptions.

@since 0.0.1

Attributes

execution_context[R]

@return [Hash{String=>String}] Context about where and how the error occurred @since 0.2.0

info[R]

@return [Hash] Additional specific data about this exception. @since 0.0.1

Public Class Methods

new(msg, info = {}, execution_context: nil) click to toggle source

Optionally add a hash of extra data, called info, to this exception. You can also add the engine's execution context, if available.

@param msg [String] The message for this Exception @since 0.0.1

Calls superclass method
# File lib/demiurge/exception.rb, line 24
def initialize(msg, info = {}, execution_context: nil)
  super(msg)
  @info = info
  @execution_context = execution_context ? execution_context.dup : nil
end

Public Instance Methods

backtrace_chain() click to toggle source
# File lib/demiurge/exception.rb, line 30
def backtrace_chain
  bt_chain = []
  cur_cause = self.cause
  while cur_cause
    bt_chain.push(self.backtrace)
    cur_cause = cur_cause.cause
  end
  bt_chain
end
formatted() click to toggle source
# File lib/demiurge/exception.rb, line 54
    def formatted
      bt = backtrace_chain.map { |t| t.join("\n") }.join("\n... Caused by ...\n")
      <<FORMATTED_BLOCK
#{self.message}
Error info: #{info.inspect}
Context: #{execution_context.inspect}
#{bt}
FORMATTED_BLOCK
    end
jsonable() click to toggle source

Serialize this exception to a JSON-serializable PORO.

@return [Hash] The serialized {Demiurge::Errors::Exception} data @since 0.0.1

# File lib/demiurge/exception.rb, line 44
def jsonable()
  bt = backtrace_chain.inject { |a, b| a + [ "... Caused by ..." ] + b }
  {
    "message" => self.message,
    "info" => self.info,
    "execution_context" => self.execution_context,
    "backtrace" => bt
  }
end