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.



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

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.



5
6
7
# File 'lib/bolt/error.rb', line 5

def details
  @details
end

#error_codeObject (readonly)

Returns the value of attribute error_code.



5
6
7
# File 'lib/bolt/error.rb', line 5

def error_code
  @error_code
end

#issue_codeObject (readonly)

Returns the value of attribute issue_code.



5
6
7
# File 'lib/bolt/error.rb', line 5

def issue_code
  @issue_code
end

#kindObject (readonly)

Returns the value of attribute kind.



5
6
7
# File 'lib/bolt/error.rb', line 5

def kind
  @kind
end

Class Method Details

.unknown_plan(plan) ⇒ Object



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

def self.unknown_plan(plan)
  new(
    "Could not find a plan named \"#{plan}\". For a list of available plans, run \"bolt plan show\"",
    'bolt/unknown-plan'
  )
end

.unknown_task(task) ⇒ Object



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

def self.unknown_task(task)
  new("Could not find a task named \"#{task}\". For a list of available tasks, run \"bolt task show\"",
      'bolt/unknown-task')
end

Instance Method Details

#msgObject



15
16
17
# File 'lib/bolt/error.rb', line 15

def msg
  message
end

#to_hObject



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

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



27
28
29
# File 'lib/bolt/error.rb', line 27

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

#to_puppet_errorObject



31
32
33
# File 'lib/bolt/error.rb', line 31

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