Class: SolidErrors::Frontend::MessageNormalizer

Inherits:
Object
  • Object
show all
Defined in:
lib/solid_errors/frontend/message_normalizer.rb

Overview

Collapses the parts of a message that vary between occurrences of the same bug.

Error backends typically fingerprint on the message (Solid Errors hashes exception class + message + severity + source), so an id, a URL or a digest inside the text would split one recurring bug into an unbounded number of groups. Normalising first keeps one bug to one row.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filters: SolidErrors::Frontend.message_filters, limit: SolidErrors::Frontend.max_message_length) ⇒ MessageNormalizer

Returns a new instance of MessageNormalizer.



15
16
17
18
# File 'lib/solid_errors/frontend/message_normalizer.rb', line 15

def initialize(filters: SolidErrors::Frontend.message_filters, limit: SolidErrors::Frontend.max_message_length)
  @filters = filters
  @limit = limit
end

Class Method Details

.call(message, filters: SolidErrors::Frontend.message_filters, limit: SolidErrors::Frontend.max_message_length) ⇒ Object



11
12
13
# File 'lib/solid_errors/frontend/message_normalizer.rb', line 11

def self.call(message, filters: SolidErrors::Frontend.message_filters, limit: SolidErrors::Frontend.max_message_length)
  new(filters: filters, limit: limit).call(message)
end

Instance Method Details

#call(message) ⇒ Object



20
21
22
23
24
# File 'lib/solid_errors/frontend/message_normalizer.rb', line 20

def call(message)
  text = message.to_s.strip.gsub(/\s+/, " ")
  text = @filters.reduce(text) { |result, (pattern, replacement)| result.gsub(pattern, replacement) }
  truncate(text)
end