Exception: Bolt::PAL::PALError

Inherits:
Error
  • Object
show all
Defined in:
lib/bolt/pal.rb

Overview

PALError is used to convert errors from executing puppet code into Bolt::Errors

Instance Attribute Summary

Attributes inherited from Error

#details, #error_code, #issue_code, #kind

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Error

#add_filelineno, #msg, #to_h, #to_json, #to_puppet_error, unknown_plan, unknown_task

Constructor Details

#initialize(msg, details = {}) ⇒ PALError

Returns a new instance of PALError.



42
43
44
# File 'lib/bolt/pal.rb', line 42

def initialize(msg, details = {})
  super(msg, 'bolt/pal-error', details)
end

Class Method Details

.from_error(err) ⇒ Object

Generate a Bolt::Pal::PALError for non-bolt errors



34
35
36
37
38
39
40
# File 'lib/bolt/pal.rb', line 34

def self.from_error(err)
  # Use the original error message if available
  message = err.cause ? err.cause.message : err.message
  e = new(message)
  e.set_backtrace(err.backtrace)
  e
end

.from_preformatted_error(err) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/bolt/pal.rb', line 16

def self.from_preformatted_error(err)
  error = if err.cause.is_a? Bolt::Error
            err.cause
          else
            from_error(err)
          end

  # Provide the location of an error if it came from a plan
  details = {}
  details[:file]   = err.file if defined?(err.file)
  details[:line]   = err.line if defined?(err.line)
  details[:column] = err.pos if defined?(err.pos)

  error.add_filelineno(details.compact)
  error
end