email_error_reporter 0.1.0.pre

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 3b5bd625697e275051c8d51cee4ccbbe14faf8aa2cf2a09c18c225292d7dbf52
4
+ data.tar.gz: 762d0ec2963ea8fe672a35732699a02c0d9da507b10e5cd100b2d5ea48650f04
5
+ SHA512:
6
+ metadata.gz: '0824b30d48460da923cadca8d6cb3ef9a2f3ec60f1ce1bba25a45cedc7c610331c477ea022a1929fc80091e4edf7bb3d5d0f02460b91488c7f0dfcac17166467'
7
+ data.tar.gz: 5dd1577971dbcd095b4a3a4658433c98cd850a07c2521dae1bf0e9d513da36370ddc9ab6866f0c1fc14c4be7b81da03b3d596a795866eaefa314fe77dee03f58
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright Niklas Haeusele
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # EmailErrorReporter
2
+
3
+ > [!CAUTION]
4
+ > This is a very early prototype
5
+
6
+ `email_error_reporter` uses the new [Rails error reporting API](https://guides.rubyonrails.org/error_reporting.html#error-reporting) to send emails whenever an exception is being reported. It works out of the box with HTTP requests, jobs and the rails runner.
7
+
8
+ ## Installation
9
+
10
+ Add the gem:
11
+
12
+ ```bash
13
+ bundle add email_error_reporter && bundle install
14
+ ```
15
+
16
+ and configure the email addresses that should receive an email in the case of an exception:
17
+
18
+ ```ruby
19
+ # application.rb
20
+ config.email_error_reporter.to = ["youremail@example.com"]
21
+ ```
22
+
23
+ `email_error_reporter` will reuse your environment specific ActionMailer configuration for delivering emails.
24
+
25
+ ## Usage
26
+
27
+ All exceptions are reported automatically. No additional code required.
28
+
29
+ Please consult the [official guides](https://guides.rubyonrails.org/error_reporting.html) for an introduction to the error reporting API.
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
+
41
+ ## License
42
+
43
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,3 @@
1
+ require "bundler/setup"
2
+
3
+ require "bundler/gem_tasks"
@@ -0,0 +1 @@
1
+ <li><%= frame %></li>
@@ -0,0 +1 @@
1
+ <p>No backtrace available</p>
@@ -0,0 +1,6 @@
1
+ <h1><%= @error.class %></h1>
2
+ <p><%= @error.message %></p>
3
+
4
+ <div>
5
+ <%= render(partial: "frame", collection: @backtrace) || render("no_backtrace") -%>
6
+ </div>
@@ -0,0 +1,17 @@
1
+ module EmailErrorReporter
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace EmailErrorReporter
4
+
5
+ config.email_error_reporter = ActiveSupport::OrderedOptions.new
6
+ config.email_error_reporter.to = []
7
+
8
+ initializer "email_error_reporter.error_subscribe" do
9
+ Rails.error.subscribe(Subscriber.new)
10
+ end
11
+
12
+ # ActiveJob cannot (de)-serialize exceptions by default
13
+ initializer "email_error_reporter.exception_serializer" do |app|
14
+ app.config.active_job.custom_serializers << ExceptionSerializer
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,18 @@
1
+ module EmailErrorReporter
2
+ class ErrorMailer < ActionMailer::Base
3
+ def error(error, handled:, severity:, context:, source: nil)
4
+ @error = error
5
+ @handled = handled
6
+ @severity = severity
7
+ @context = context
8
+ @source = source
9
+
10
+ @backtrace = Array.wrap(error.backtrace)
11
+
12
+ mail(
13
+ subject: "#{error.class}",
14
+ to: Rails.application.config.email_error_reporter.to
15
+ )
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,23 @@
1
+ module EmailErrorReporter
2
+ class ExceptionSerializer < ActiveJob::Serializers::ObjectSerializer
3
+ def serialize(exception)
4
+ super(
5
+ exception_class: exception.class.to_s,
6
+ message: exception.message,
7
+ backtrace: exception.backtrace
8
+ )
9
+ end
10
+
11
+ def deserialize(hash)
12
+ hash[:exception_class].constantize.new(hash[:message]).tap do |e|
13
+ e.set_backtrace(hash[:backtrace])
14
+ end
15
+ end
16
+
17
+ private
18
+
19
+ def klass
20
+ Exception
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,11 @@
1
+ module EmailErrorReporter
2
+ class Subscriber
3
+ def report(error, handled:, severity:, context:, source: nil)
4
+ ErrorMailer.error(error,
5
+ handled: handled,
6
+ context: context,
7
+ severity: severity,
8
+ source: source).deliver_later
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module EmailErrorReporter
2
+ VERSION = "0.1.0.pre"
3
+ end
@@ -0,0 +1,10 @@
1
+ require "email_error_reporter/version"
2
+ require "email_error_reporter/engine"
3
+
4
+ module EmailErrorReporter
5
+ extend ActiveSupport::Autoload
6
+
7
+ autoload :ErrorMailer
8
+ autoload :Subscriber
9
+ autoload :ExceptionSerializer
10
+ end
@@ -0,0 +1,12 @@
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
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: email_error_reporter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0.pre
5
+ platform: ruby
6
+ authors:
7
+ - Niklas Haeusele
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-01-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 7.1.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 7.1.2
27
+ description: Report your Rails errors via email.
28
+ email:
29
+ - niklas.haeusele@hey.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - MIT-LICENSE
35
+ - README.md
36
+ - Rakefile
37
+ - app/views/email_error_reporter/error_mailer/_frame.html.erb
38
+ - app/views/email_error_reporter/error_mailer/_no_backtrace.html.erb
39
+ - app/views/email_error_reporter/error_mailer/error.html.erb
40
+ - lib/email_error_reporter.rb
41
+ - lib/email_error_reporter/engine.rb
42
+ - lib/email_error_reporter/error_mailer.rb
43
+ - lib/email_error_reporter/exception_serializer.rb
44
+ - lib/email_error_reporter/subscriber.rb
45
+ - lib/email_error_reporter/version.rb
46
+ - lib/tasks/email_error_reporter_tasks.rake
47
+ homepage: https://github.com/codergeek121/email_error_reporter
48
+ licenses:
49
+ - MIT
50
+ metadata:
51
+ allowed_push_host: https://rubygems.org
52
+ homepage_uri: https://github.com/codergeek121/email_error_reporter
53
+ source_code_uri: https://github.com/codergeek121/email_error_reporter
54
+ post_install_message:
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ requirements: []
69
+ rubygems_version: 3.5.3
70
+ signing_key:
71
+ specification_version: 4
72
+ summary: Report your Rails errors via email.
73
+ test_files: []