# class Chef::Formatters::ErrorInspectors::RegistrationErrorInspector

## RegistrationErrorInspector¶ ↑

Wraps exceptions that occur during the client registration process and suggests possible causes.

### Attributes

config[R]
exception[R]
node_name[R]

### Public Class Methods

new(node_name, exception, config) click to toggle source

    # File lib/chef/formatters/error_inspectors/registration_error_inspector.rb, line 16
    def initialize(node_name, exception, config)
      @node_name = node_name
      @exception = exception
      @config = config
    end

### Public Instance Methods

add_explanation(error_description) click to toggle source

    # File lib/chef/formatters/error_inspectors/registration_error_inspector.rb, line 22
            def add_explanation(error_description)
              case exception
              when Net::HTTPServerException, Net::HTTPFatalError
                humanize_http_exception(error_description)
              when Errno::ECONNREFUSED, Timeout::Error, Errno::ETIMEDOUT, SocketError
                error_description.section("Network Error:","There was a network error connecting to the Chef Server:
    #{exception.message}
    ")
                error_description.section("Relevant Config Settings:","chef_server_url  "#{server_url}"

    If your chef_server_url is correct, your network could be down.
    ")
              when Chef::Exceptions::PrivateKeyMissing
                error_description.section("Private Key Not Found:","Your private key could not be loaded. If the key file exists, ensure that it is
    readable by chef-client.
    ")
                error_description.section("Relevant Config Settings:","validation_key "#{api_key}"
    ")
              when Chef::Exceptions::InvalidRedirect
                error_description.section("Invalid Redirect:","Change your server location in client.rb to the server's FQDN to avoid unwanted redirections.
    ")
              else
                "#{exception.class.name}: #{exception.message}"
              end
            end

api_key() click to toggle source

    # File lib/chef/formatters/error_inspectors/registration_error_inspector.rb, line 115
    def api_key
      config[:validation_key]
      #config[:client_key]
    end

clock_skew?() click to toggle source

    # File lib/chef/formatters/error_inspectors/registration_error_inspector.rb, line 124
    def clock_skew?
      exception.response.body =~ /synchronize the clock/i
    end

format_rest_error() click to toggle source

Parses JSON from the error response sent by Chef Server and returns the error message

    # File lib/chef/formatters/error_inspectors/registration_error_inspector.rb, line 132
    def format_rest_error
      Array(Chef::JSONCompat.from_json(exception.response.body)["error"]).join('; ')
    rescue Exception
      exception.response.body
    end

humanize_http_exception(error_description) click to toggle source

    # File lib/chef/formatters/error_inspectors/registration_error_inspector.rb, line 53
            def humanize_http_exception(error_description)
              response = exception.response
              case response
              when Net::HTTPUnauthorized
                if clock_skew?
                  error_description.section("Authentication Error:","Failed to authenticate to the chef server (http 401).
    The request failed because your clock has drifted by more than 15 minutes.
    Syncing your clock to an NTP Time source should resolve the issue.
    ")
                else
                  error_description.section("Authentication Error:","Failed to authenticate to the chef server (http 401).
    ")

                  error_description.section("Server Response:", format_rest_error)
                  error_description.section("Relevant Config Settings:","chef_server_url         "#{server_url}"
    validation_client_name  "#{username}"
    validation_key          "#{api_key}"

    If these settings are correct, your validation_key may be invalid.
    ")
                end
              when Net::HTTPForbidden
                error_description.section("Authorization Error:","Your validation client is not authorized to create the client for this node (HTTP 403).
    ")
                error_description.section("Possible Causes:","* There may already be a client named "#{config[:node_name]}"
    * Your validation client (#{username}) may have misconfigured authorization permissions.
    ")
              when Net::HTTPBadRequest
                error_description.section("Invalid Request Data:","The data in your request was invalid (HTTP 400).
    ")
                error_description.section("Server Response:",format_rest_error)
              when Net::HTTPNotFound
                error_description.section("Resource Not Found:","The server returned a HTTP 404. This usually indicates that your chef_server_url is incorrect.
    ")
                error_description.section("Relevant Config Settings:","chef_server_url "#{server_url}"
    ")
              when Net::HTTPInternalServerError
                error_description.section("Unknown Server Error:","The server had a fatal error attempting to load the node data.
    ")
                error_description.section("Server Response:", format_rest_error)
              when Net::HTTPBadGateway, Net::HTTPServiceUnavailable
                error_description.section("Server Unavailable","The Chef Server is temporarily unavailable")
                error_description.section("Server Response:", format_rest_error)
              else
                error_description.section("Unexpected API Request Failure:", format_rest_error)
              end
            end

server_url() click to toggle source

    # File lib/chef/formatters/error_inspectors/registration_error_inspector.rb, line 120
    def server_url
      config[:chef_server_url]
    end

username() click to toggle source

    # File lib/chef/formatters/error_inspectors/registration_error_inspector.rb, line 110
    def username
      #config[:node_name]
      config[:validation_client_name]
    end