Exception: Prismic::Error

Inherits:
Exception
  • Object
show all
Defined in:
lib/prismic.rb

Overview

These exception can contains an error cause and is able to show them

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(msg = nil, cause = nil) ⇒ Error

Returns a new instance of Error.



19
20
21
22
# File 'lib/prismic.rb', line 19

def initialize(msg=nil, cause=nil)
  msg ? super(msg) : msg
  @cause = cause
end

Instance Attribute Details

#causeObject (readonly)

Returns the value of attribute cause.



18
19
20
# File 'lib/prismic.rb', line 18

def cause
  @cause
end

Instance Method Details

#full_trace(e = self) ⇒ String

Return the full trace of the error (including nested errors)

Parameters:

  • e (Exception) (defaults to: self)

    Parent error (for internal use)

Returns:

  • (String)

    The trace



28
29
30
31
32
33
34
35
36
# File 'lib/prismic.rb', line 28

def full_trace(e=self)
  first, *backtrace = e.backtrace
  msg = e == self ? "" : "Caused by "
  msg += "#{first}: #{e.message} (#{e.class})"
  stack = backtrace.map{|s| "\tfrom #{s}" }.join("\n")
  cause = e.respond_to?(:cause) ? e.cause : nil
  cause_stack = cause ? full_trace(cause) : nil
  [msg, stack, cause_stack].compact.join("\n")
end