Exception: Demiurge::Errors::Exception
- Inherits:
-
RuntimeError
- Object
- RuntimeError
- Demiurge::Errors::Exception
- Defined in:
- lib/demiurge/exception.rb
Overview
Demiurge::Errors::Exception is the parent class of all Demiurge-specific Exceptions.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#execution_context ⇒ Hash{String=>String}
readonly
Context about where and how the error occurred.
-
#info ⇒ Hash
readonly
Additional specific data about this exception.
Instance Method Summary collapse
- #backtrace_chain ⇒ Object
- #formatted ⇒ Object
-
#initialize(msg, info = {}, execution_context: nil) ⇒ Exception
constructor
Optionally add a hash of extra data, called info, to this exception.
-
#jsonable ⇒ Hash
Serialize this exception to a JSON-serializable PORO.
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.
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_context ⇒ Hash{String=>String} (readonly)
Returns Context about where and how the error occurred
16 17 18 |
# File 'lib/demiurge/exception.rb', line 16 def execution_context @execution_context end |
#info ⇒ Hash (readonly)
Returns Additional specific data about this exception.
12 13 14 |
# File 'lib/demiurge/exception.rb', line 12 def info @info end |
Instance Method Details
#backtrace_chain ⇒ Object
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 |
#formatted ⇒ Object
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.} Error info: #{info.inspect} Context: #{execution_context.inspect} #{bt} FORMATTED_BLOCK end |
#jsonable ⇒ Hash
Serialize this exception to a JSON-serializable PORO.
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., "info" => self.info, "execution_context" => self.execution_context, "backtrace" => bt } end |