Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Gemfile
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added it as a development dependency anyway

Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ gem "rake", "~> 13.0"
gem "minitest", "~> 5.0"

gem "standard", "~> 1.3"

gem "actionmailer", ">= 7.0"
8 changes: 4 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ PATH
remote: .
specs:
solid_errors (0.6.1)
actionmailer (>= 7.0)
actionpack (>= 7.0)
actionview (>= 7.0)
activerecord (>= 7.0)
Expand Down Expand Up @@ -63,7 +62,7 @@ GEM
concurrent-ruby (1.3.4)
connection_pool (2.4.1)
crass (1.0.6)
date (3.3.4)
date (3.4.1)
drb (2.2.1)
erubi (1.13.0)
globalid (1.2.1)
Expand All @@ -88,14 +87,14 @@ GEM
net-smtp
mini_mime (1.1.5)
minitest (5.25.1)
net-imap (0.4.14)
net-imap (0.5.6)
date
net-protocol
net-pop (0.1.2)
net-protocol
net-protocol (0.2.2)
timeout
net-smtp (0.5.0)
net-smtp (0.5.1)
net-protocol
nokogiri (1.16.7-arm64-darwin)
racc (~> 1.4)
Expand Down Expand Up @@ -188,6 +187,7 @@ PLATFORMS
x86_64-linux

DEPENDENCIES
actionmailer (>= 7.0)
minitest (~> 5.0)
rake (~> 13.0)
solid_errors!
Expand Down
5 changes: 4 additions & 1 deletion app/mailers/solid_errors/error_mailer.rb
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Zeitwerk of course complains if the class is not defined. I looked if I could exclude only this class from eager_loading and requiring it manually only if ActionMailer::Base is defined, but I did not figure out how.
This is the approach I figured: I always define it, and raise if ActionMailer is actually not there. I don't really have performance consent, and we should never reach this point anyway (see below).

Yes, it smells a bit to be honest, so I could investigate more if you think I should.

Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
module SolidErrors
# adapted from: https://github.com/codergeek121/email_error_reporter/blob/main/lib/email_error_reporter/error_mailer.rb
class ErrorMailer < ActionMailer::Base
class ErrorMailer < (defined?(ActionMailer::Base) ? ActionMailer::Base : Object)
def error_occurred(occurrence)
unless defined?(ActionMailer::Base)
raise "ActionMailer is not available. Make sure that you require \"action_mailer/railtie\" in application.rb"
end
@occurrence = occurrence
@error = occurrence.error
subject = "#{@error.severity_emoji} #{@error.exception_class}"
Expand Down
5 changes: 5 additions & 0 deletions lib/solid_errors/engine.rb
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what I'd do: immediatly check if we want to send emails but ActionMailer is not there: show a nice error message and explain how it can be fixed.

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ class Engine < ::Rails::Engine
config.solid_errors.each do |name, value|
SolidErrors.public_send(:"#{name}=", value)
end

if SolidErrors.send_emails? && !defined?(ActionMailer)
raise "You have configured solid_errors.send_emails = true but ActionMailer is not available." \
"Make sure that you require \"action_mailer/railtie\" in application.rb or set solid_errors.send_emails = false."
end
end

initializer "solid_errors.active_record.error_subscriber" do
Expand Down
1 change: 0 additions & 1 deletion solid_errors.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ Gem::Specification.new do |spec|
end

">= 7.0".tap do |rails_version|
spec.add_dependency "actionmailer", rails_version
spec.add_dependency "actionpack", rails_version
spec.add_dependency "actionview", rails_version
spec.add_dependency "activerecord", rails_version
Expand Down
Loading