Sha256: 6f24865b2a72054250df74f8830358072231bc4cc60d119d6fd9bd4ff4d6232b

Contents?: true

Size: 726 Bytes

Versions: 13

Compression:

Stored size: 726 Bytes

Contents

module Bugsnag::Middleware
  class SuggestionData

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

    def initialize(bugsnag)
      @bugsnag = bugsnag
    end

    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
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
bugsnag-6.6.3 lib/bugsnag/middleware/suggestion_data.rb
bugsnag-6.6.2 lib/bugsnag/middleware/suggestion_data.rb
bugsnag-6.6.1 lib/bugsnag/middleware/suggestion_data.rb
bugsnag-6.6.0 lib/bugsnag/middleware/suggestion_data.rb
bugsnag-6.5.0 lib/bugsnag/middleware/suggestion_data.rb
bugsnag-6.4.0 lib/bugsnag/middleware/suggestion_data.rb
bugsnag-6.3.0 lib/bugsnag/middleware/suggestion_data.rb
bugsnag-6.3.0.beta.0 lib/bugsnag/middleware/suggestion_data.rb
bugsnag-6.2.0 lib/bugsnag/middleware/suggestion_data.rb
bugsnag-6.1.1 lib/bugsnag/middleware/suggestion_data.rb
bugsnag-6.1.0 lib/bugsnag/middleware/suggestion_data.rb
bugsnag-6.0.1 lib/bugsnag/middleware/suggestion_data.rb
bugsnag-6.0.0 lib/bugsnag/middleware/suggestion_data.rb