class Chef::Application::ExitCode
These are the exit codes defined in the exit codes design document github.com/chef/chef/blob/main/docs/dev/design_documents/client_exit_codes.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 108 def client_upgraded?(exception) resolve_exception_array(exception).any?(Chef::Exceptions::ClientUpgraded) end
configuration_failure?(exception)
click to toggle source
# File lib/chef/application/exit_code.rb, line 104 def configuration_failure?(exception) resolve_exception_array(exception).any?(Chef::Exceptions::ConfigurationError) 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 141 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/blob/main/docs/dev/design_documents/client_exit_codes.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 134 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 100 def reboot_failed?(exception) resolve_exception_array(exception).any?(Chef::Exceptions::RebootFailed) end
reboot_needed?(exception)
click to toggle source
# File lib/chef/application/exit_code.rb, line 96 def reboot_needed?(exception) resolve_exception_array(exception).any?(Chef::Exceptions::RebootPending) 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?(Chef::Exceptions::Reboot) end
resolve_exception_array(exception)
click to toggle source
# File lib/chef/application/exit_code.rb, line 120 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 112 def sigint_received?(exception) resolve_exception_array(exception).any?(Chef::Exceptions::SigInt) end
sigterm_received?(exception)
click to toggle source
# File lib/chef/application/exit_code.rb, line 116 def sigterm_received?(exception) resolve_exception_array(exception).any?(Chef::Exceptions::SigTerm) end
valid_exit_codes()
click to toggle source
# File lib/chef/application/exit_code.rb, line 130 def valid_exit_codes VALID_RFC_062_EXIT_CODES.values end