Exception: Demiurge::Errors::Exception

Inherits:
RuntimeError
  • Object
show all
Defined in:
lib/demiurge/exception.rb

Overview

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

Since:

  • 0.0.1

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(msg, info = {}, execution_context: nil) ⇒ Exception

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

Parameters:

  • msg (String)

    The message for this Exception

Since:

  • 0.0.1



24
25
26
27
28
# 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

Instance Attribute Details

#execution_contextHash{String=>String} (readonly)

Returns Context about where and how the error occurred

Returns:

  • (Hash{String=>String})

    Context about where and how the error occurred

Since:

  • 0.2.0



16
17
18
# File 'lib/demiurge/exception.rb', line 16

def execution_context
  @execution_context
end

#infoHash (readonly)

Returns Additional specific data about this exception.

Returns:

  • (Hash)

    Additional specific data about this exception.

Since:

  • 0.0.1



12
13
14
# File 'lib/demiurge/exception.rb', line 12

def info
  @info
end

Instance Method Details

#backtrace_chainObject

Since:

  • 0.0.1



30
31
32
33
34
35
36
37
38
# 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

#formattedObject

Since:

  • 0.0.1



54
55
56
57
58
59
60
61
62
# 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

#jsonableHash

Serialize this exception to a JSON-serializable PORO.

Returns:

Since:

  • 0.0.1



44
45
46
47
48
49
50
51
52
# 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