Module: Karafka::Web::Tracking::Helpers::ErrorInfo

Included in:
Consumers::Listeners::Errors, Producers::Listeners::Errors
Defined in:
lib/karafka/web/tracking/helpers/error_info.rb

Overview

Module containing some helper methods useful for extracting extra errors info

Instance Method Summary collapse

Instance Method Details

#extract_error_info(error) ⇒ Array<String, String, String>

Extracts the basic error info

Parameters:

  • error (StandardError)

    error that occurred

Returns:

  • (Array<String, String, String>)

    array with error name, message and backtrace



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/karafka/web/tracking/helpers/error_info.rb', line 14

def extract_error_info(error)
  app_root = "#{::Karafka.root}/"

  gem_home = if ENV.key?('GEM_HOME')
               ENV['GEM_HOME']
             else
               File.expand_path(File.join(Karafka.gem_root.to_s, '../'))
             end

  gem_home = "#{gem_home}/"

  backtrace = error.backtrace || []
  backtrace.map! { |line| line.gsub(app_root, '') }
  backtrace.map! { |line| line.gsub(gem_home, '') }

  [
    error.class.name,
    extract_error_message(error),
    backtrace.join("\n")
  ]
end

#extract_error_message(error) ⇒ String

Returns formatted exception message.

Parameters:

  • error (StandardError)

    error that occurred

Returns:

  • (String)

    formatted exception message



38
39
40
41
42
43
44
45
# File 'lib/karafka/web/tracking/helpers/error_info.rb', line 38

def extract_error_message(error)
  error_message = error.message.to_s[0, 10_000]
  error_message.force_encoding('utf-8')
  error_message.scrub! if error_message.respond_to?(:scrub!)
  error_message
rescue StandardError
  '!!! Error message extraction failed !!!'
end