Method: Turbot::Helpers#format_error

Defined in:
lib/turbot/helpers.rb

#format_error(error, message = 'Turbot client internal error.') ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/turbot/helpers.rb', line 24

def format_error(error, message = 'Turbot client internal error.')
  formatted_error = []
  formatted_error << " !    #{message}"
  formatted_error << ' !    Report a bug at: https://github.com/openc/turbot-client/issues/new'
  formatted_error << ''
  formatted_error << "    Error:       #{error.message} (#{error.class})"
  formatted_error << "    Backtrace:   #{error.backtrace.first}"
  error.backtrace[1..-1].each do |line|
    formatted_error << "                 #{line}"
  end
  if error.backtrace.length > 1
    formatted_error << ''
  end
  command = ARGV.map do |arg|
    if arg.include?(' ')
      arg = %{"#{arg}"}
    else
      arg
    end
  end.join(' ')
  formatted_error << "    Command:     turbot #{command}"
  unless host == DEFAULT_HOST
    formatted_error << "    Host:        #{host}"
  end
  formatted_error << "    Version:     #{Turbot::DEBUG_VERSION}"
  formatted_error << "\n"
  formatted_error.join("\n")
end