Class: RedmineAirbrakeBackend::IosReport

Inherits:
Error
  • Object
show all
Defined in:
lib/redmine_airbrake_backend/ios_report.rb

Overview

iOS Report received by airbrake

Instance Attribute Summary

Attributes inherited from Error

#application, #attachments, #backtrace, #id, #message, #subject, #type

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ IosReport

Returns a new instance of IosReport.



7
8
9
# File 'lib/redmine_airbrake_backend/ios_report.rb', line 7

def initialize(data)
  super(IosReport.parse(data))
end

Class Method Details

.parse(data) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
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
52
53
54
55
56
# File 'lib/redmine_airbrake_backend/ios_report.rb', line 13

def self.parse(data)
  error = {
    application: {},
    backtrace:   [],
    attachments: [],
  }

  header_finished      = false
  next_line_is_message = false
  crashed_thread       = false
  indicent_identifier  = nil

  data.split("\n").each do |line|
    header_finished = true if line =~ /^(Application Specific Information|Last Exception Backtrace|Thread \d+( Crashed)?):$/

    unless header_finishedii
      ii = parse_header_line(line, error)
      indicent_identifier ||= ii if ii
    end

    if next_line_is_message
      next_line_is_message = false

      parse_message(line, error)
    end

    crashed_thread = false if line =~ /^Thread \d+:$/

    error[:backtrace] << parse_backtrace_element(line) if crashed_thread

    crashed_thread = true if error[:backtrace].compact.blank? && line =~ /^(Last Exception Backtrace|Thread \d+ Crashed):$/

    next_line_is_message = true if line =~ /^Application Specific Information:$/
  end

  return nil if error.blank?

  error[:attachments] << {
    filename: "#{indicent_identifier}.crash",
    data:     data
  } if indicent_identifier.present?

  error
end

.parse_backtrace_element(line) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
# File 'lib/redmine_airbrake_backend/ios_report.rb', line 90

def self.parse_backtrace_element(line)
  if line =~ /^(\d+)\s+([^\s]+)\s+(0x[0-9a-f]+)\s+(.+) \+ (\d+)$/
    {
      file:     Regexp.last_match(2),
      function: Regexp.last_match(4),
      line:     Regexp.last_match(5)
    }
  else
    nil
  end
end

.parse_header_line(line, error) ⇒ Object



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

def self.parse_header_line(line, error)
  key, value = line.split(':', 2).map { |s| s.strip }

  return nil if key.blank? || value.blank?

  case key
  when 'Exception Type'
    error[:type] = value
  when 'Exception Codes'
    error[:message] = value
  when 'Incident Identifier'
    return value
  when 'Identifier'
    error[:application][:name] = value
  when 'Version'
    error[:application][:version] = value
  end

  nil
end

.parse_message(line, error) ⇒ Object



79
80
81
82
83
84
85
86
87
88
# File 'lib/redmine_airbrake_backend/ios_report.rb', line 79

def self.parse_message(line, error)
  error[:message] = line

  if line =~ /^\*\*\* Terminating app due to uncaught exception '([^']+)', reason: '\*\*\* (.*)'$/
    error[:type]    = Regexp.last_match(1)
    error[:message] = Regexp.last_match(2)
  else
    error[:message] = line
  end
end