File tree Expand file tree Collapse file tree 4 files changed +54
-4
lines changed
dummy/config/environments Expand file tree Collapse file tree 4 files changed +54
-4
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,16 @@ All exceptions are reported automatically. No additional code required.
28
28
29
29
Please consult the [ official guides] ( https://guides.rubyonrails.org/error_reporting.html ) for an introduction to the error reporting API.
30
30
31
+ ## Test your setup
32
+
33
+ You can use the built-in rake task ` rake email_error_reporter:check ` to check if everything works correctly in your setup.
34
+
35
+ If you're using Kamal, you can run the following command to test the setup in production:
36
+
37
+ ```
38
+ kamal app exec -p 'bundle exec rake email_error_reporter:test_email'
39
+ ```
40
+
31
41
## License
32
42
33
43
The gem is available as open source under the terms of the [ MIT License] ( https://opensource.org/licenses/MIT ) .
Original file line number Diff line number Diff line change 1
- # desc "Explaining what the task does"
2
- # task :email_error_reporter do
3
- # # Task goes here
4
- # end
1
+ desc "Report a test exception"
2
+ namespace :email_error_reporter do
3
+ task check : :environment do
4
+ Rails . error . handle { raise "This is a test!" }
5
+ $stdout. puts <<~TXT
6
+ Test exception triggered.
7
+
8
+ Recipients:
9
+ #{ Rails . application . config . email_error_reporter . to . join ( "\n " ) . gsub ( /^/ , "* " ) }
10
+ TXT
11
+ end
12
+ end
Original file line number Diff line number Diff line change 73
73
74
74
# Raise error when a before_action's only/except options reference missing actions
75
75
config . action_controller . raise_on_missing_callback_actions = true
76
+
77
+ config . email_error_reporter . to = [ "[email protected] " ]
76
78
end
Original file line number Diff line number Diff line change
1
+ require "test_helper"
2
+
3
+ class EmailErrorReporter ::ErrorMailerTest < ActionMailer ::TestCase
4
+ test "renders the template correctly" do
5
+ exception = Exception . new ( "some message" )
6
+ email = EmailErrorReporter ::ErrorMailer . error (
7
+ exception ,
8
+ handled : true ,
9
+ severity : :info ,
10
+ context : { }
11
+ )
12
+ assert_equal [ ] , email . to
13
+ assert_equal "Exception" , email . subject
14
+ assert_equal read_fixture ( "error" ) . join , email . body . to_s
15
+ end
16
+
17
+ test "renders a backtrace" do
18
+ exception = Exception . new ( "some message" )
19
+ exception . set_backtrace ( [ "foo" , "bar" ] )
20
+ email = EmailErrorReporter ::ErrorMailer . error (
21
+ exception ,
22
+ handled : true ,
23
+ severity : :info ,
24
+ context : { }
25
+ )
26
+ assert_equal [ ] , email . to
27
+ assert_equal "Exception" , email . subject
28
+ assert_equal read_fixture ( "error_with_backtrace" ) . join , email . body . to_s
29
+ end
30
+ end
You can’t perform that action at this time.
0 commit comments