Exception: Bolt::Error

Inherits:
RuntimeError
  • Object
show all
Defined in:
lib/bolt/error.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(msg, kind, details = nil, issue_code = nil) ⇒ Error

Returns a new instance of Error.



9
10
11
12
13
14
15
# File 'lib/bolt/error.rb', line 9

def initialize(msg, kind, details = nil, issue_code = nil)
  super(msg)
  @kind = kind
  @issue_code = issue_code
  @details = details || {}
  @error_code ||= 1
end

Instance Attribute Details

#detailsObject (readonly)

Returns the value of attribute details.



7
8
9
# File 'lib/bolt/error.rb', line 7

def details
  @details
end

#error_codeObject (readonly)

Returns the value of attribute error_code.



7
8
9
# File 'lib/bolt/error.rb', line 7

def error_code
  @error_code
end

#issue_codeObject (readonly)

Returns the value of attribute issue_code.



7
8
9
# File 'lib/bolt/error.rb', line 7

def issue_code
  @issue_code
end

#kindObject (readonly)

Returns the value of attribute kind.



7
8
9
# File 'lib/bolt/error.rb', line 7

def kind
  @kind
end

Class Method Details

.unknown_plan(plan) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/bolt/error.rb', line 49

def self.unknown_plan(plan)
  command = Bolt::Util.powershell? ? "Get-BoltPlan" : "bolt plan show"
  new(
    "Could not find a plan named '#{plan}'. For a list of available plans, run '#{command}'.",
    'bolt/unknown-plan'
  )
end

.unknown_task(task) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/bolt/error.rb', line 41

def self.unknown_task(task)
  command = Bolt::Util.powershell? ? "Get-BoltTask" : "bolt task show"
  new(
    "Could not find a task named '#{task}'. For a list of available tasks, run '#{command}'.",
    'bolt/unknown-task'
  )
end

Instance Method Details

#add_filelineno(details) ⇒ Object



29
30
31
# File 'lib/bolt/error.rb', line 29

def add_filelineno(details)
  @details.merge!(details) unless @details['file']
end

#msgObject



17
18
19
# File 'lib/bolt/error.rb', line 17

def msg
  message
end

#to_hObject



21
22
23
24
25
26
27
# File 'lib/bolt/error.rb', line 21

def to_h
  h = { 'kind' => kind,
        'msg' => message,
        'details' => details }
  h['issue_code'] = issue_code if issue_code
  h
end

#to_json(opts = nil) ⇒ Object



33
34
35
# File 'lib/bolt/error.rb', line 33

def to_json(opts = nil)
  to_h.to_json(opts)
end

#to_puppet_errorObject



37
38
39
# File 'lib/bolt/error.rb', line 37

def to_puppet_error
  Puppet::DataTypes::Error.from_asserted_hash(to_h)
end