Class: ErrorReport

Inherits:
Object
  • Object
show all
Defined in:
app/models/error_report.rb

Overview

Processes a new error report.

Accepts a hash with the following attributes:

  • :error_class - the class of error

  • :message - the error message

  • :backtrace - an array of stack trace lines

  • :request - a hash of values describing the request

  • :server_environment - a hash of values describing the server environment

  • :notifier - information to identify the source of the error report

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml_or_attributes) ⇒ ErrorReport

Returns a new instance of ErrorReport


25
26
27
28
29
30
# File 'app/models/error_report.rb', line 25

def initialize(xml_or_attributes)
  @attributes = xml_or_attributes
  @attributes = Hoptoad.parse_xml!(@attributes) if @attributes.is_a? String
  @attributes = @attributes.with_indifferent_access
  @attributes.each { |k, v| instance_variable_set(:"@#{k}", v) }
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key


18
19
20
# File 'app/models/error_report.rb', line 18

def api_key
  @api_key
end

#error_classObject (readonly)

Returns the value of attribute error_class


18
19
20
# File 'app/models/error_report.rb', line 18

def error_class
  @error_class
end

#frameworkObject (readonly)

Returns the value of attribute framework


18
19
20
# File 'app/models/error_report.rb', line 18

def framework
  @framework
end

#messageObject (readonly)

Returns the value of attribute message


18
19
20
# File 'app/models/error_report.rb', line 18

def message
  @message
end

#noticeObject (readonly)

Returns the value of attribute notice


18
19
20
# File 'app/models/error_report.rb', line 18

def notice
  @notice
end

#notifierObject (readonly)

Returns the value of attribute notifier


18
19
20
# File 'app/models/error_report.rb', line 18

def notifier
  @notifier
end

#requestObject (readonly)

Returns the value of attribute request


18
19
20
# File 'app/models/error_report.rb', line 18

def request
  @request
end

#server_environmentObject (readonly)

Returns the value of attribute server_environment


18
19
20
# File 'app/models/error_report.rb', line 18

def server_environment
  @server_environment
end

#user_attributesObject (readonly)

Returns the value of attribute user_attributes


18
19
20
# File 'app/models/error_report.rb', line 18

def user_attributes
  @user_attributes
end

Instance Method Details

#appObject


38
39
40
# File 'app/models/error_report.rb', line 38

def app
  @app ||= App.where(api_key: api_key).first
end

#backtraceObject


42
43
44
# File 'app/models/error_report.rb', line 42

def backtrace
  @normalized_backtrace ||= Backtrace.find_or_create(raw: @backtrace)
end

#errorError

Error associate to this error_report

Can already exist or not

Returns:

  • (Error)

69
70
71
72
73
74
75
# File 'app/models/error_report.rb', line 69

def error
  @error ||= app.find_or_create_err!(
    error_class: error_class,
    environment: rails_env,
    fingerprint: fingerprint
  )
end

#generate_notice!Object


46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/models/error_report.rb', line 46

def generate_notice!
  return unless valid?
  return @notice if @notice
  @notice = Notice.new(
    message: message,
    error_class: error_class,
    backtrace_id: backtrace.id,
    request: request,
    server_environment: server_environment,
    notifier: notifier,
    user_attributes: user_attributes,
    framework: framework
  )
  error.notices << @notice
  @notice
end

#rails_envObject


32
33
34
35
36
# File 'app/models/error_report.rb', line 32

def rails_env
  rails_env = server_environment['environment-name']
  rails_env = 'development' if rails_env.blank?
  rails_env
end

#should_keep?Boolean

Returns:

  • (Boolean)

81
82
83
84
85
86
87
# File 'app/models/error_report.rb', line 81

def should_keep?
  app_version = server_environment['app-version'] || ''
  current_version = app.current_app_version
  return true unless current_version.present?
  return false if app_version.length <= 0
  Gem::Version.new(app_version) >= Gem::Version.new(current_version)
end

#valid?Boolean

Returns:

  • (Boolean)

77
78
79
# File 'app/models/error_report.rb', line 77

def valid?
  app.present?
end