Skip to content

Commit df6b44f

Browse files
committed
Merge remote-tracking branch 'upstream/main'
2 parents fdf8906 + bd61a79 commit df6b44f

11 files changed

Lines changed: 52 additions & 13 deletions

File tree

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ gem "rake", "~> 13.0"
1010
gem "minitest", "~> 5.0"
1111

1212
gem "standard", "~> 1.3"
13+
14+
gem "actionmailer", ">= 7.0"

Gemfile.lock

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
solid_errors (0.7.0)
4+
solid_errors (0.6.1)
55
actionmailer (>= 7.0)
66
actionpack (>= 7.0)
77
actionview (>= 7.0)
@@ -63,7 +63,7 @@ GEM
6363
concurrent-ruby (1.3.4)
6464
connection_pool (2.4.1)
6565
crass (1.0.6)
66-
date (3.3.4)
66+
date (3.4.1)
6767
drb (2.2.1)
6868
erubi (1.13.0)
6969
globalid (1.2.1)
@@ -88,18 +88,18 @@ GEM
8888
net-smtp
8989
mini_mime (1.1.5)
9090
minitest (5.25.1)
91-
net-imap (0.4.14)
91+
net-imap (0.5.6)
9292
date
9393
net-protocol
9494
net-pop (0.1.2)
9595
net-protocol
9696
net-protocol (0.2.2)
9797
timeout
98-
net-smtp (0.5.0)
98+
net-smtp (0.5.1)
9999
net-protocol
100-
nokogiri (1.18.6-arm64-darwin)
100+
nokogiri (1.18.2-arm64-darwin)
101101
racc (~> 1.4)
102-
nokogiri (1.18.6-x86_64-linux-gnu)
102+
nokogiri (1.18.2-x86_64-linux-gnu)
103103
racc (~> 1.4)
104104
parallel (1.26.3)
105105
parser (3.3.4.2)
@@ -158,8 +158,8 @@ GEM
158158
rubocop-ast (>= 1.31.1, < 2.0)
159159
ruby-progressbar (1.13.0)
160160
securerandom (0.3.1)
161-
sqlite3 (2.6.0-arm64-darwin)
162-
sqlite3 (2.6.0-x86_64-linux-gnu)
161+
sqlite3 (2.5.0-arm64-darwin)
162+
sqlite3 (2.5.0-x86_64-linux-gnu)
163163
standard (1.40.0)
164164
language_server-protocol (~> 3.17.0.2)
165165
lint_roller (~> 1.0)
@@ -188,6 +188,7 @@ PLATFORMS
188188
x86_64-linux
189189

190190
DEPENDENCIES
191+
actionmailer (>= 7.0)
191192
minitest (~> 5.0)
192193
rake (~> 13.0)
193194
solid_errors!

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ $ rails solid_errors:install_migrations
103103

104104
All exceptions are recorded automatically. No additional code required.
105105

106+
You can add default additional information to the context of the error by adding this line to your application controller:
107+
```ruby
108+
before_action { Rails.error.set_context(request_url: request.original_url, params: params, session: session.inspect) }
109+
```
110+
The additional context information will be automatically displayed on the occurence details page.
111+
106112
Please consult the [official guides](https://guides.rubyonrails.org/error_reporting.html) for an introduction to the error reporting API.
107113

108114
There are intentionally few features; you can view and resolve errors. That’s it. The goal is to provide a simple, lightweight, and performant solution for tracking exceptions in your Rails application. If you need more features, you should probably use a 3rd party service like [Honeybadger](https://www.honeybadger.io/), whose MIT-licensed [Ruby agent gem](https://github.com/honeybadger-io/honeybadger-ruby) provided a couple of critical pieces of code for this project.
@@ -166,6 +172,7 @@ You can configure Solid Errors via the Rails configuration object, under the `so
166172
* `email_from` - The email address to send a notification from. See [Email notifications](#email-notifications) for more information.
167173
* `email_to` - The email address(es) to send a notification to. See [Email notifications](#email-notifications) for more information.
168174
* `email_subject_prefix` - Prefix added to the subject line for email notifications. See [Email notifications](#email-notifications) for more information.
175+
* `base_controller_class` - Specify a different controller as the base class for the Solid Errors controller. See [Authentication](#authentication) for more information.
169176

170177
### Database Configuration
171178

@@ -222,6 +229,13 @@ authenticate :user, -> (user) { user.admin? } do
222229
end
223230
```
224231

232+
You can also specify a different controller to use as the Solid Errors controller base class:
233+
234+
```ruby
235+
# Override the base controller class with your own controller
236+
config.solid_errors.base_controller_class = "YourAdminController"
237+
```
238+
225239
#### Email notifications
226240

227241
Solid Errors _can_ send email notifications whenever an error occurs, if your application has ActionMailer already properly setup to send emails. However, in order to activate this feature you must define the email address(es) to send the notifications to. Optionally, you can also define the email address to send the notifications from (useful if your email provider only allows emails to be sent from a predefined list of addresses) or simply turn off this feature altogether. You can also define a subject prefix for the email notifications to quickly identify the source of the error.

app/controllers/solid_errors/application_controller.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module SolidErrors
2-
class ApplicationController < ActionController::Base
2+
class ApplicationController < SolidErrors.base_controller_class.constantize
3+
layout "solid_errors/application"
34
protect_from_forgery with: :exception
45

56
http_basic_authenticate_with name: SolidErrors.username, password: SolidErrors.password if SolidErrors.password

app/mailers/solid_errors/error_mailer.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
module SolidErrors
22
# adapted from: https://github.com/codergeek121/email_error_reporter/blob/main/lib/email_error_reporter/error_mailer.rb
3-
class ErrorMailer < ActionMailer::Base
3+
class ErrorMailer < (defined?(ActionMailer::Base) ? ActionMailer::Base : Object)
44
def error_occurred(occurrence)
5+
unless defined?(ActionMailer::Base)
6+
raise "ActionMailer is not available. Make sure that you require \"action_mailer/railtie\" in application.rb"
7+
end
58
@occurrence = occurrence
69
@error = occurrence.error
710
subject = "#{@error.severity_emoji} #{@error.exception_class}"

bin/console

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# frozen_string_literal: true
33

44
require "bundler/setup"
5+
require "rails"
56
require "solid_errors"
67

78
# You can add fixtures and/or initialization code here to make experimenting

lib/solid_errors.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
module SolidErrors
99
mattr_accessor :connects_to
1010
mattr_accessor :full_backtrace
11+
mattr_accessor :base_controller_class, default: "::ActionController::Base"
1112
mattr_writer :username
1213
mattr_writer :password
1314
mattr_writer :send_emails
@@ -28,8 +29,6 @@ def username
2829
@username ||= ENV["SOLIDERRORS_USERNAME"] || @@username
2930
end
3031

31-
# use method instead of attr_accessor to ensure
32-
# this works if variable set after SolidErrors is loaded
3332
def password
3433
@password ||= ENV["SOLIDERRORS_PASSWORD"] || @@password
3534
end

lib/solid_errors/engine.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ class Engine < ::Rails::Engine
1010
config.solid_errors.each do |name, value|
1111
SolidErrors.public_send(:"#{name}=", value)
1212
end
13+
14+
if SolidErrors.send_emails? && !defined?(ActionMailer)
15+
raise "You have configured solid_errors.send_emails = true but ActionMailer is not available." \
16+
"Make sure that you require \"action_mailer/railtie\" in application.rb or set solid_errors.send_emails = false."
17+
end
1318
end
1419

1520
initializer "solid_errors.active_record.error_subscriber" do

solid_errors.gemspec

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ Gem::Specification.new do |spec|
2121
end
2222

2323
">= 7.0".tap do |rails_version|
24-
spec.add_dependency "actionmailer", rails_version
2524
spec.add_dependency "actionpack", rails_version
2625
spec.add_dependency "actionview", rails_version
2726
spec.add_dependency "activerecord", rails_version

test/test_backtrace.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# frozen_string_literal: true
2+
3+
require "test_helper"
4+
5+
class TestSolidErrors < Minitest::Test
6+
def test_backtrace
7+
backtrace = SolidErrors::Backtrace.parse(caller(0)).to_a
8+
assert_includes backtrace[0][:method], "test_backtrace"
9+
end
10+
end

0 commit comments

Comments
 (0)