Skip to content

Commit cf0afbc

Browse files
committed
Merge remote-tracking branch 'upstream/main'
2 parents 5d0faf3 + bab17b5 commit cf0afbc

File tree

18 files changed

+191
-69
lines changed

18 files changed

+191
-69
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@
88
/tmp/
99
.DS_Store
1010
test/dummy/log/*.log
11-
.idea
11+
test/dummy/db/*.sqlite3
12+
.idea

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
## [Unreleased]
22

3+
## [0.7.0] - 2025-06-11
4+
5+
- support ruby 3.4.0 style backtrace string ([@kuboon](https://github.com/fractaledmind/solid_errors/pull/74))
6+
- Remove ActionMailer as a dependency ([@coorasse](https://github.com/fractaledmind/solid_errors/pull/77))
7+
- Fix console uninitialized constant Rails error ([@ron-shinall](https://github.com/fractaledmind/solid_errors/pull/72))
8+
- Update documentation to show how to add additional information to the context ([@francescob](https://github.com/fractaledmind/solid_errors/pull/71))
9+
- Introduce base_controller_class config option ([@ron-shinall](https://github.com/fractaledmind/solid_errors/pull/67))
10+
- Introducing destroy_after config property to clear resolved errors ([@ron-shinall](https://github.com/fractaledmind/solid_errors/pull/79))
11+
- configuration for a subject prefix for email ([@francescob](https://github.com/fractaledmind/solid_errors/pull/66))
12+
- fix some small typos ([@defkode](https://github.com/fractaledmind/solid_errors/pull/64))
13+
314
## [0.6.1] - 2024-09-19
415

516
- Fix the install generator by putting the schema in the db/ directory ([@fractaledmind](https://github.com/fractaledmind/solid_errors/pull/62))

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
solid_errors (0.6.1)
4+
solid_errors (0.7.0)
55
actionpack (>= 7.0)
66
actionview (>= 7.0)
77
activerecord (>= 7.0)

README.md

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,8 @@
2424
</a>
2525
</p>
2626

27-
2827
Solid Errors is a DB-based, app-internal exception tracker for Rails applications, designed with simplicity and performance in mind. It uses the new [Rails error reporting API](https://guides.rubyonrails.org/error_reporting.html) to store uncaught exceptions in the database, and provides a simple UI for viewing and managing exceptions.
2928

30-
> [!WARNING]
31-
> The current point release of Rails (7.1.3.2) has a bug which severely limits the utility of Solid Errors. Exceptions raised during a web request *are not* reported to Rails' error reporter. There is a fix in the `main` branch, but it has not been released in a new point release. As such, Solid Errors is **not** production-ready unless you are running Rails from the `main` branch or until a new point version is released and you upgrade.
32-
> The original bug report can be found [here](https://github.com/rails/rails/issues/51002) and the pull request making the fix is [here](https://github.com/rails/rails/pull/51050). I will try to backport the fix into the gem directly, but I haven't quite figured it out yet.
33-
3429

3530
## Installation
3631

@@ -173,6 +168,7 @@ You can configure Solid Errors via the Rails configuration object, under the `so
173168
* `email_to` - The email address(es) to send a notification to. See [Email notifications](#email-notifications) for more information.
174169
* `email_subject_prefix` - Prefix added to the subject line for email notifications. See [Email notifications](#email-notifications) for more information.
175170
* `base_controller_class` - Specify a different controller as the base class for the Solid Errors controller. See [Authentication](#authentication) for more information.
171+
* `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.
176172

177173
### Database Configuration
178174

@@ -264,6 +260,20 @@ If you have set `send_emails` to `true` and have set an `email_to` address, Soli
264260

265261
If you have not set `send_emails` to `true` or have not set an `email_to` address, Solid Errors will not send any email notifications.
266262

263+
#### Automatically destroying old records
264+
265+
Setting `destroy_after` to a duration will allow Solid Errors to be self-maintaining by peridically destroying **resolved** records that are older than that value. The value provided must respond to `.ago`.
266+
267+
```ruby
268+
# Automatically destroy records older than 30 days
269+
config.solid_errors.destroy_after = 30.days
270+
```
271+
272+
```ruby
273+
# Automatically destroy records older than 6 months
274+
config.solid_errors.destroy_after = 6.months
275+
```
276+
267277
### Examples
268278

269279
There are only two screens in the dashboard.
@@ -359,7 +369,7 @@ You can always take control of the views by creating your own views and/or parti
359369

360370
## Development
361371

362-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
372+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. If you want to set up a local development database, run `rake db:migrate`.
363373

364374
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
365375

Rakefile

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
# frozen_string_literal: true
22

3+
require "bundler/setup"
4+
5+
APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
6+
load "rails/tasks/engine.rake"
7+
38
require "bundler/gem_tasks"
49
require "rake/testtask"
10+
require "standard/rake"
11+
12+
task default: %i[test standard]
513

614
Rake::TestTask.new(:test) do |t|
715
t.libs << "test"
816
t.libs << "lib"
9-
t.test_files = FileList["test/**/test_*.rb"]
17+
t.test_files = FileList["test/**/*_test.rb"]
1018
end
11-
12-
require "standard/rake"
13-
14-
task default: %i[test standard]

app/models/solid_errors/occurrence.rb

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ module SolidErrors
22
class Occurrence < Record
33
belongs_to :error, class_name: "SolidErrors::Error"
44

5-
after_create_commit :send_email, if: :should_send_email?
5+
after_create_commit :send_email, if: -> { SolidErrors.send_emails? && SolidErrors.email_to.present? }
6+
after_create_commit :clear_resolved_errors, if: :should_clear_resolved_errors?
67

78
# The parsed exception backtrace. Lines in this backtrace that are from installed gems
89
# have the base path for gem installs replaced by "[GEM_ROOT]", while those in the project
@@ -24,12 +25,25 @@ def send_email
2425
ErrorMailer.error_occurred(self).deliver_later
2526
end
2627

27-
def should_send_email?
28-
return false unless SolidErrors.send_emails?
29-
return false unless SolidErrors.email_to.present?
30-
return true if error.occurrences.one?
28+
def clear_resolved_errors
29+
transaction do
30+
SolidErrors::Occurrence
31+
.where(error: SolidErrors::Error.resolved)
32+
.where(created_at: ...SolidErrors.destroy_after.ago)
33+
.delete_all
34+
SolidErrors::Error.resolved
35+
.where
36+
.missing(:occurrences)
37+
.delete_all
38+
end
39+
end
40+
41+
def should_clear_resolved_errors?
42+
return false unless SolidErrors.destroy_after
43+
return false unless SolidErrors.destroy_after.respond_to?(:ago)
44+
return false unless (id % 100).zero?
3145

32-
error.occurrences.where(created_at: error.prev_resolved_at..).one?
46+
true
3347
end
3448
end
3549
end

lib/solid_errors.rb

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ module SolidErrors
1111
mattr_accessor :base_controller_class, default: "::ActionController::Base"
1212
mattr_writer :username
1313
mattr_writer :password
14-
mattr_writer :send_emails
15-
mattr_writer :email_from
16-
mattr_writer :email_to
17-
mattr_writer :email_subject_prefix
14+
mattr_accessor :send_emails, default: false
15+
mattr_accessor :email_from, default: "[email protected]"
16+
mattr_accessor :email_to
17+
mattr_accessor :email_subject_prefix
18+
mattr_accessor :destroy_after
1819

1920
class << self
2021
# use method instead of attr_accessor to ensure
@@ -25,28 +26,19 @@ def full_backtrace?
2526

2627
# use method instead of attr_accessor to ensure
2728
# this works if variable set after SolidErrors is loaded
29+
# this works if ENV variable set after SolidErrors is loaded
2830
def username
2931
@username ||= ENV["SOLIDERRORS_USERNAME"] || @@username
3032
end
3133

34+
# use method instead of attr_accessor to ensure
35+
# this works if ENV variable set after SolidErrors is loaded
3236
def password
3337
@password ||= ENV["SOLIDERRORS_PASSWORD"] || @@password
3438
end
3539

3640
def send_emails?
37-
@send_emails ||= ENV["SOLIDERRORS_SEND_EMAILS"] || @@send_emails || false
38-
end
39-
40-
def email_from
41-
@email_from ||= ENV["SOLIDERRORS_EMAIL_FROM"] || @@email_from || "[email protected]"
42-
end
43-
44-
def email_to
45-
@email_to ||= ENV["SOLIDERRORS_EMAIL_TO"] || @@email_to
46-
end
47-
48-
def email_subject_prefix
49-
@email_subject_prefix ||= ENV["SOLIDERRORS_EMAIL_SUBJECT_PREFIX"] || @@email_subject_prefix
41+
send_emails && email_to.present?
5042
end
5143
end
5244
end

lib/solid_errors/subscriber.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def report(error, handled:, severity:, context:, source: nil)
4343

4444
SolidErrors::Occurrence.create(
4545
error_id: record.id,
46-
backtrace: backtrace.join("\n"),
46+
backtrace: error.backtrace&.join("\n"),
4747
context: s(context)
4848
)
4949
end

test/dummy/Rakefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Add your own tasks in files placed in lib/tasks ending in .rake,
2+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3+
4+
require_relative "config/application"
5+
6+
Rails.application.load_tasks

test/dummy/config/database.yml

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,42 +9,15 @@ default: &default
99
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
1010
timeout: 5000
1111

12-
primary: &primary
13-
<<: *default
14-
database: storage/<%= ENV.fetch("RAILS_ENV", "development") %>.sqlite3
15-
16-
queue: &queue
17-
<<: *default
18-
migrations_paths: db/queue_migrate
19-
database: storage/queue.sqlite3
20-
21-
errors: &errors
22-
<<: *default
23-
migrations_paths: db/errors_migrate
24-
database: storage/errors.sqlite3
25-
2612
development:
2713
primary:
28-
<<: *primary
29-
database: storage/<%= `git branch --show-current`.chomp || 'development' %>.sqlite3
30-
queue: *queue
31-
errors: *errors
14+
<<: *default
15+
database: db/development.sqlite3
3216

3317
# Warning: The database defined as "test" will be erased and
3418
# re-generated from your development database when you run "rake".
3519
# Do not set this db to the same as development or production.
3620
test:
3721
primary:
38-
<<: *primary
22+
<<: *default
3923
database: db/test.sqlite3
40-
queue:
41-
<<: *queue
42-
database: db/queue.sqlite3
43-
errors:
44-
<<: *errors
45-
database: db/errors.sqlite3
46-
47-
production:
48-
primary: *primary
49-
queue: *queue
50-
errors: *errors

0 commit comments

Comments
 (0)