Skip to content

Commit 4b5807c

Browse files
committed
Merge branch 'main' into clear-resolved-errors
2 parents da248f9 + bd61a79 commit 4b5807c

File tree

13 files changed

+53
-14
lines changed

13 files changed

+53
-14
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ jobs:
1717
- '3.1.4'
1818
- '3.2.3'
1919
- '3.3.0'
20+
- '3.4.0'
2021
steps:
2122
- uses: actions/checkout@v4
2223
- name: Set up Ruby

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: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ PATH
22
remote: .
33
specs:
44
solid_errors (0.6.1)
5-
actionmailer (>= 7.0)
65
actionpack (>= 7.0)
76
actionview (>= 7.0)
87
activerecord (>= 7.0)
@@ -63,7 +62,7 @@ GEM
6362
concurrent-ruby (1.3.4)
6463
connection_pool (2.4.1)
6564
crass (1.0.6)
66-
date (3.3.4)
65+
date (3.4.1)
6766
drb (2.2.1)
6867
erubi (1.13.0)
6968
globalid (1.2.1)
@@ -88,18 +87,18 @@ GEM
8887
net-smtp
8988
mini_mime (1.1.5)
9089
minitest (5.25.1)
91-
net-imap (0.4.14)
90+
net-imap (0.5.6)
9291
date
9392
net-protocol
9493
net-pop (0.1.2)
9594
net-protocol
9695
net-protocol (0.2.2)
9796
timeout
98-
net-smtp (0.5.0)
97+
net-smtp (0.5.1)
9998
net-protocol
100-
nokogiri (1.16.7-arm64-darwin)
99+
nokogiri (1.18.2-arm64-darwin)
101100
racc (~> 1.4)
102-
nokogiri (1.16.7-x86_64-linux)
101+
nokogiri (1.18.2-x86_64-linux-gnu)
103102
racc (~> 1.4)
104103
parallel (1.26.3)
105104
parser (3.3.4.2)
@@ -158,8 +157,8 @@ GEM
158157
rubocop-ast (>= 1.31.1, < 2.0)
159158
ruby-progressbar (1.13.0)
160159
securerandom (0.3.1)
161-
sqlite3 (2.0.4-arm64-darwin)
162-
sqlite3 (2.0.4-x86_64-linux-gnu)
160+
sqlite3 (2.5.0-arm64-darwin)
161+
sqlite3 (2.5.0-x86_64-linux-gnu)
163162
standard (1.40.0)
164163
language_server-protocol (~> 3.17.0.2)
165164
lint_roller (~> 1.0)
@@ -188,6 +187,7 @@ PLATFORMS
188187
x86_64-linux
189188

190189
DEPENDENCIES
190+
actionmailer (>= 7.0)
191191
minitest (~> 5.0)
192192
rake (~> 13.0)
193193
solid_errors!

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ end
9898

9999
All exceptions are recorded automatically. No additional code required.
100100

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

103109
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.
@@ -161,6 +167,7 @@ You can configure Solid Errors via the Rails configuration object, under the `so
161167
* `email_from` - The email address to send a notification from. See [Email notifications](#email-notifications) for more information.
162168
* `email_to` - The email address(es) to send a notification to. See [Email notifications](#email-notifications) for more information.
163169
* `email_subject_prefix` - Prefix added to the subject line for email notifications. See [Email notifications](#email-notifications) for more information.
170+
* `base_controller_class` - Specify a different controller as the base class for the Solid Errors controller. See [Authentication](#authentication) for more information.
164171
* `destroy_after` - If set, Solid Errors will periodically destroy resolved records that are older than the value specified. See [Automatically destroying old records](#automatically-destroying-old-records) for more information.
165172

166173
### Database Configuration
@@ -218,6 +225,13 @@ authenticate :user, -> (user) { user.admin? } do
218225
end
219226
```
220227

228+
You can also specify a different controller to use as the Solid Errors controller base class:
229+
230+
```ruby
231+
# Override the base controller class with your own controller
232+
config.solid_errors.base_controller_class = "YourAdminController"
233+
```
234+
221235
#### Email notifications
222236

223237
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}"

app/models/solid_errors/backtrace_line.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module SolidErrors
22
# adapted from: https://github.com/honeybadger-io/honeybadger-ruby/blob/master/lib/honeybadger/backtrace.rb
33
class BacktraceLine
44
# Backtrace line regexp (optionally allowing leading X: for windows support).
5-
INPUT_FORMAT = %r{^((?:[a-zA-Z]:)?[^:]+):(\d+)(?::in `([^']+)')?$}
5+
INPUT_FORMAT = %r{^((?:[a-zA-Z]:)?[^:]+):(\d+)(?::in [`']([^']+)')?$}
66
STRING_EMPTY = "".freeze
77
GEM_ROOT = "[GEM_ROOT]".freeze
88
PROJECT_ROOT = "[PROJECT_ROOT]".freeze

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
@@ -7,6 +7,7 @@
77

88
module SolidErrors
99
mattr_accessor :connects_to
10+
mattr_accessor :base_controller_class, default: "::ActionController::Base"
1011
mattr_writer :username
1112
mattr_writer :password
1213
mattr_writer :send_emails
@@ -22,8 +23,6 @@ def username
2223
@username ||= ENV["SOLIDERRORS_USERNAME"] || @@username
2324
end
2425

25-
# use method instead of attr_accessor to ensure
26-
# this works if variable set after SolidErrors is loaded
2726
def password
2827
@password ||= ENV["SOLIDERRORS_PASSWORD"] || @@password
2928
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

0 commit comments

Comments
 (0)