Class: Bugsnag::Middleware::SuggestionData

Inherits:
Object
  • Object
show all
Defined in:
lib/bugsnag/middleware/suggestion_data.rb

Overview

Attaches any “Did you mean?” suggestions to the report

Constant Summary collapse

CAPTURE_REGEX =
/Did you mean\?([\s\S]+)$/
DELIMITER =
"\n"

Instance Method Summary collapse

Constructor Details

#initialize(bugsnag) ⇒ SuggestionData

Returns a new instance of SuggestionData.


9
10
11
# File 'lib/bugsnag/middleware/suggestion_data.rb', line 9

def initialize(bugsnag)
  @bugsnag = bugsnag
end

Instance Method Details

#call(report) ⇒ Object


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/bugsnag/middleware/suggestion_data.rb', line 13

def call(report)
  matches = []
  report.raw_exceptions.each do |exception|
    match = CAPTURE_REGEX.match(exception.message)
    next unless match

    suggestions = match.captures[0].split(DELIMITER)
    matches.concat suggestions.map{ |suggestion| suggestion.strip }
  end

  if matches.size == 1
    report.add_tab(:error, {:suggestion => matches.first})
  elsif matches.size > 1
    report.add_tab(:error, {:suggestions => matches})
  end

  @bugsnag.call(report)
end