Sha256: ed596cd4908aafe515facdb2d18cd77ff4784b1bba90f5b65fafcf8bfb20b467

Contents?: true

Size: 790 Bytes

Versions: 29

Compression:

Stored size: 790 Bytes

Contents

module Bugsnag::Middleware
  ##
  # Attaches any "Did you mean?" suggestions to the report
  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

29 entries across 29 versions & 1 rubygems

Version Path
bugsnag-6.25.0 lib/bugsnag/middleware/suggestion_data.rb
bugsnag-6.24.2 lib/bugsnag/middleware/suggestion_data.rb
bugsnag-6.24.1 lib/bugsnag/middleware/suggestion_data.rb
bugsnag-6.24.0 lib/bugsnag/middleware/suggestion_data.rb
bugsnag-6.23.0 lib/bugsnag/middleware/suggestion_data.rb
bugsnag-6.22.1 lib/bugsnag/middleware/suggestion_data.rb
bugsnag-6.21.0 lib/bugsnag/middleware/suggestion_data.rb
bugsnag-6.20.0 lib/bugsnag/middleware/suggestion_data.rb
bugsnag-6.19.0 lib/bugsnag/middleware/suggestion_data.rb
bugsnag-6.18.0 lib/bugsnag/middleware/suggestion_data.rb
bugsnag-6.17.0 lib/bugsnag/middleware/suggestion_data.rb
bugsnag-6.16.0 lib/bugsnag/middleware/suggestion_data.rb
bugsnag-6.15.0 lib/bugsnag/middleware/suggestion_data.rb
bugsnag-6.14.0 lib/bugsnag/middleware/suggestion_data.rb
bugsnag-6.13.1 lib/bugsnag/middleware/suggestion_data.rb
bugsnag-6.13.0 lib/bugsnag/middleware/suggestion_data.rb
bugsnag-6.12.2 lib/bugsnag/middleware/suggestion_data.rb
bugsnag-6.12.1 lib/bugsnag/middleware/suggestion_data.rb
bugsnag-6.12.0 lib/bugsnag/middleware/suggestion_data.rb
bugsnag-6.11.1 lib/bugsnag/middleware/suggestion_data.rb