Class: ActiveMail::ParseErrorReporter

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/activemail/parse_error_reporter.rb

Overview

Surfaces libxml2 recover-mode repairs that would otherwise silently change the rendered email, honoring ActiveMail.configuration.on_parse_error.

Instance Method Summary collapse

Constructor Details

#initialize(known_tags) ⇒ ParseErrorReporter

Returns a new instance of ParseErrorReporter.



15
16
17
18
# File 'lib/activemail/parse_error_reporter.rb', line 15

def initialize(known_tags)
  # dup.freeze: the caller's array stays decoupled and cannot be mutated under us.
  @known_tags = T.let(known_tags.dup.freeze, T::Array[String])
end

Instance Method Details

#call(errors) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/activemail/parse_error_reporter.rb', line 21

def call(errors)
  mode = ::ActiveMail.configuration.on_parse_error
  return if mode == :ignore

  relevant = errors.reject { |error| known_tag_error?(error) }
  return if relevant.empty?

  messages = relevant.map { |error| error.message.to_s.strip }.join('; ')
  raise ActiveMail::ParseError, messages if mode == :raise

  ::ActiveMail.log_warning("[activemail] HTML parse issues: #{messages}")
end