Class: Chef::Formatters::ErrorInspectors::CookbookSyncErrorInspector

Inherits:
Object
  • Object
show all
Includes:
APIErrorFormatting
Defined in:
lib/chef/formatters/error_inspectors/cookbook_sync_error_inspector.rb

Overview

== CookbookSyncErrorInspector Generates human-friendly explanations for errors encountered during

cookbook sync.

TODO: Not sure what errors are commonly seen during cookbook sync, so the messaging is kinda generic.

Constant Summary

Constants included from APIErrorFormatting

APIErrorFormatting::NETWORK_ERROR_CLASSES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from APIErrorFormatting

#api_key, #clock_skew?, #describe_400_error, #describe_401_error, #describe_406_error, #describe_500_error, #describe_503_error, #describe_eof_error, #describe_http_error, #describe_network_errors, #format_rest_error, #safe_format_rest_error, #server_url, #username

Constructor Details

#initialize(cookbooks, exception) ⇒ CookbookSyncErrorInspector

Returns a new instance of CookbookSyncErrorInspector.



38
39
40
# File 'lib/chef/formatters/error_inspectors/cookbook_sync_error_inspector.rb', line 38

def initialize(cookbooks, exception)
  @cookbooks, @exception = cookbooks, exception
end

Instance Attribute Details

#cookbooksObject (readonly)

Returns the value of attribute cookbooks.



36
37
38
# File 'lib/chef/formatters/error_inspectors/cookbook_sync_error_inspector.rb', line 36

def cookbooks
  @cookbooks
end

#exceptionObject (readonly)

Returns the value of attribute exception.



35
36
37
# File 'lib/chef/formatters/error_inspectors/cookbook_sync_error_inspector.rb', line 35

def exception
  @exception
end

Instance Method Details

#add_explanation(error_description) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/chef/formatters/error_inspectors/cookbook_sync_error_inspector.rb', line 42

def add_explanation(error_description)
  case exception
  when Net::HTTPClientException, Net::HTTPFatalError
    humanize_http_exception(error_description)
  when EOFError
    describe_eof_error(error_description)
  when *NETWORK_ERROR_CLASSES
    describe_network_errors(error_description)
  else
    error_description.section("Unexpected Error:", "#{exception.class.name}: #{exception.message}")
  end
end

#configObject



55
56
57
# File 'lib/chef/formatters/error_inspectors/cookbook_sync_error_inspector.rb', line 55

def config
  Chef::Config
end

#humanize_http_exception(error_description) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/chef/formatters/error_inspectors/cookbook_sync_error_inspector.rb', line 59

def humanize_http_exception(error_description)
  response = exception.response
  case response
  when Net::HTTPUnauthorized
    # TODO: this is where you'd see conflicts b/c of username/clientname stuff
    describe_401_error(error_description)
  when Net::HTTPBadRequest
    describe_400_error(error_description)
  when Net::HTTPNotFound
  when Net::HTTPInternalServerError
    describe_500_error(error_description)
  when Net::HTTPBadGateway, Net::HTTPServiceUnavailable, Net::HTTPGatewayTimeOut
    describe_503_error(error_description)
  when Net::HTTPNotAcceptable
    describe_406_error(error_description, response)
  else
    describe_http_error(error_description)
  end
end