class Chef::Application::ExitCode

These are the exit codes defined in Chef RFC 062 github.com/chef/chef-rfc/blob/master/rfc062-exit-status.md

Constants

DEPRECATED_RFC_062_EXIT_CODES
VALID_RFC_062_EXIT_CODES

-1 is defined as DEPRECATED_FAILURE in RFC 062, so it is not enumerated in an active constant.

Public Class Methods

normalize_exit_code(exit_code = nil) click to toggle source
# File lib/chef/application/exit_code.rb, line 49
def normalize_exit_code(exit_code = nil)
  normalized_exit_code = normalize_legacy_exit_code(exit_code)
  if valid_exit_codes.include? normalized_exit_code
    normalized_exit_code
  else
    Chef::Log.warn(non_standard_exit_code_warning(normalized_exit_code))
    VALID_RFC_062_EXIT_CODES[:GENERIC_FAILURE]
  end
end

Private Class Methods

client_upgraded?(exception) click to toggle source
# File lib/chef/application/exit_code.rb, line 116
def client_upgraded?(exception)
  resolve_exception_array(exception).any? do |e|
    e.is_a? Chef::Exceptions::ClientUpgraded
  end
end
configuration_failure?(exception) click to toggle source
# File lib/chef/application/exit_code.rb, line 110
def configuration_failure?(exception)
  resolve_exception_array(exception).any? do |e|
    e.is_a? Chef::Exceptions::ConfigurationError
  end
end
lookup_exit_code_by_exception(exception) click to toggle source
# File lib/chef/application/exit_code.rb, line 72
def lookup_exit_code_by_exception(exception)
  if sigint_received?(exception)
    VALID_RFC_062_EXIT_CODES[:SIGINT_RECEIVED]
  elsif sigterm_received?(exception)
    VALID_RFC_062_EXIT_CODES[:SIGTERM_RECEIVED]
  elsif reboot_scheduled?(exception)
    VALID_RFC_062_EXIT_CODES[:REBOOT_SCHEDULED]
  elsif reboot_needed?(exception)
    VALID_RFC_062_EXIT_CODES[:REBOOT_NEEDED]
  elsif reboot_failed?(exception)
    VALID_RFC_062_EXIT_CODES[:REBOOT_FAILED]
  elsif configuration_failure?(exception)
    VALID_RFC_062_EXIT_CODES[:CONFIG_FAILURE]
  elsif client_upgraded?(exception)
    VALID_RFC_062_EXIT_CODES[:CLIENT_UPGRADED]
  else
    VALID_RFC_062_EXIT_CODES[:GENERIC_FAILURE]
  end
end
non_standard_exit_code_warning(exit_code) click to toggle source
# File lib/chef/application/exit_code.rb, line 155
def non_standard_exit_code_warning(exit_code)
  "#{ChefUtils::Dist::Infra::CLIENT} attempted to exit with a non-standard exit code of #{exit_code}." \
  " The #{ChefUtils::Dist::Infra::PRODUCT} Exit Codes design document (https://github.com/chef/chef-rfc/blob/master/rfc062-exit-status.md)" \
  " defines the exit codes that should be used with #{ChefUtils::Dist::Infra::CLIENT}. Chef::Application::ExitCode defines"  \
  " valid exit codes Non-standard exit codes are redefined as GENERIC_FAILURE."
end
normalize_legacy_exit_code(exit_code) click to toggle source
# File lib/chef/application/exit_code.rb, line 61
def normalize_legacy_exit_code(exit_code)
  case exit_code
  when Integer
    exit_code
  when Exception
    lookup_exit_code_by_exception(exit_code)
  else
    VALID_RFC_062_EXIT_CODES[:GENERIC_FAILURE]
  end
end
notify_on_deprecation(message) click to toggle source
# File lib/chef/application/exit_code.rb, line 148
def notify_on_deprecation(message)
  Chef.deprecated(:exit_code, message)
rescue Chef::Exceptions::DeprecatedFeatureError
  # Have to rescue this, otherwise this unhandled error preempts
  # the current exit code assignment.
end
reboot_failed?(exception) click to toggle source
# File lib/chef/application/exit_code.rb, line 104
def reboot_failed?(exception)
  resolve_exception_array(exception).any? do |e|
    e.is_a? Chef::Exceptions::RebootFailed
  end
end
reboot_needed?(exception) click to toggle source
# File lib/chef/application/exit_code.rb, line 98
def reboot_needed?(exception)
  resolve_exception_array(exception).any? do |e|
    e.is_a? Chef::Exceptions::RebootPending
  end
end
reboot_scheduled?(exception) click to toggle source
# File lib/chef/application/exit_code.rb, line 92
def reboot_scheduled?(exception)
  resolve_exception_array(exception).any? do |e|
    e.is_a? Chef::Exceptions::Reboot
  end
end
resolve_exception_array(exception) click to toggle source
# File lib/chef/application/exit_code.rb, line 134
def resolve_exception_array(exception)
  exception_array = [exception]
  if exception.respond_to?(:wrapped_errors)
    exception.wrapped_errors.each do |e|
      exception_array.push e
    end
  end
  exception_array
end
sigint_received?(exception) click to toggle source
# File lib/chef/application/exit_code.rb, line 122
def sigint_received?(exception)
  resolve_exception_array(exception).any? do |e|
    e.is_a? Chef::Exceptions::SigInt
  end
end
sigterm_received?(exception) click to toggle source
# File lib/chef/application/exit_code.rb, line 128
def sigterm_received?(exception)
  resolve_exception_array(exception).any? do |e|
    e.is_a? Chef::Exceptions::SigTerm
  end
end
valid_exit_codes() click to toggle source
# File lib/chef/application/exit_code.rb, line 144
def valid_exit_codes
  VALID_RFC_062_EXIT_CODES.values
end