Class: ChefApply::Errors::StandardErrorResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/chef_apply/errors/standard_error_resolver.rb

Overview

Provides mappings of common errors that we don’t explicitly handle, but can offer expanded help text around.

Class Method Summary collapse

Class Method Details

.depsObject



38
39
40
41
42
# File 'lib/chef_apply/errors/standard_error_resolver.rb', line 38

def self.deps
  # Avoid loading additional includes until they're needed
  require "socket" unless defined?(Socket)
  require "openssl" unless defined?(OpenSSL)
end

.resolve_exception(exception) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/chef_apply/errors/standard_error_resolver.rb', line 6

def self.resolve_exception(exception)
  deps
  show_log = true
  show_stack = true
  case exception
  when OpenSSL::SSL::SSLError
    if exception.message =~ /SSL.*verify failed.*/
      id = "CHEFNET002"
      show_log = false
      show_stack = false
    end
  when SocketError then id = "CHEFNET001"; show_log = false; show_stack = false
  end
  if id.nil?
    exception
  else
    e = ChefApply::Error.new(id, exception.message)
    e.show_log = show_log
    e.show_stack = show_stack
    e
  end
end

.unwrap_exception(wrapper) ⇒ Object



34
35
36
# File 'lib/chef_apply/errors/standard_error_resolver.rb', line 34

def self.unwrap_exception(wrapper)
  resolve_exception(wrapper.contained_exception)
end

.wrap_exception(original, target_host = nil) ⇒ Object



29
30
31
32
# File 'lib/chef_apply/errors/standard_error_resolver.rb', line 29

def self.wrap_exception(original, target_host = nil)
  resolved_exception = resolve_exception(original)
  WrappedError.new(resolved_exception, target_host)
end