Exception: Kube::CommandError

Inherits:
Error
  • Object
show all
Defined in:
lib/kube/errors.rb

Overview

Raised when a kubectl command fails.

begin
  resource.patch
rescue Kube::CommandError => e
  e.subcommand  # => "patch"
  e.stderr      # => "Error from server (NotFound): ..."
  e.exit_code   # => 1
  e.reason      # => "NotFound"  (parsed from stderr, or nil)
end

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message = nil, subcommand: nil, stderr: nil, exit_code: nil, reason: nil) ⇒ CommandError

Returns a new instance of CommandError.



22
23
24
25
26
27
28
# File 'lib/kube/errors.rb', line 22

def initialize(message = nil, subcommand: nil, stderr: nil, exit_code: nil, reason: nil)
  @subcommand = subcommand
  @stderr     = stderr
  @exit_code  = exit_code
  @reason     = reason || parse_reason(stderr)
  super(message || build_message)
end

Instance Attribute Details

#exit_codeObject (readonly)

Returns the value of attribute exit_code.



20
21
22
# File 'lib/kube/errors.rb', line 20

def exit_code
  @exit_code
end

#reasonObject (readonly)

Returns the value of attribute reason.



20
21
22
# File 'lib/kube/errors.rb', line 20

def reason
  @reason
end

#stderrObject (readonly)

Returns the value of attribute stderr.



20
21
22
# File 'lib/kube/errors.rb', line 20

def stderr
  @stderr
end

#subcommandObject (readonly)

Returns the value of attribute subcommand.



20
21
22
# File 'lib/kube/errors.rb', line 20

def subcommand
  @subcommand
end

Class Method Details

.from_kubectl(subcommand:, stderr:, exit_code:) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/kube/errors.rb', line 30

def self.from_kubectl(subcommand:, stderr:, exit_code:)
  new(
    subcommand: subcommand,
    stderr: stderr,
    exit_code: exit_code
  )
end