email_error_reporter 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8e8f1858125082a54222230c31cc9f86977225bb52e4d58250415c6b0cb7c47d
4
- data.tar.gz: 2c6a173d38e6d7b58cfea1291dfd5aa2dce6dd5b31e5907fe72772c96055ab8f
3
+ metadata.gz: ee23af096b0b064122aea6388f90bc20f65aceda47d46bcda13dedae3336919a
4
+ data.tar.gz: 5b45ec6a4fd3be12fca5cdf207295516f74653b96d1e73d6f8b4d18788608702
5
5
  SHA512:
6
- metadata.gz: 928f4ed5561244626c6968949f531931ac2d24daa8d85912346d6c80ea4b06789a678af0f03767c4170fe8d0021392a09ab60dafa1a5d4a50827e41893460376
7
- data.tar.gz: e4c5f4044e603434cd92504f37c386af900cbb1351abc6b7270a34268aed6d4a2d73a05b138f583b37ff9229583bd6d2c899c0fa8bf8321a989b833eadee5c74
6
+ metadata.gz: d7e432538fc9ff269c3c9c3e5c2a2faf2432a736279e5e0e47b694db7f909e3316bc753b1c1512a61465ed119efa440f54bdba2c10cff8b4b0ecd7d421310739
7
+ data.tar.gz: 0f3b60c8dd71f1e7437dc00a093dbf8d16d891b6be93827eca983ff1b9246e1bd427c443e8b84202063c35742a586ebaee6ea3424c80615e37c0cc7cc844108c
data/README.md CHANGED
@@ -1,28 +1,52 @@
1
1
  # EmailErrorReporter
2
- Short description and motivation.
3
2
 
4
- ## Usage
5
- How to use my plugin.
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.
6
7
 
7
8
  ## Installation
8
- Add this line to your application's Gemfile:
9
9
 
10
- ```ruby
11
- gem "email_error_reporter"
12
- ```
10
+ Add the gem:
13
11
 
14
- And then execute:
15
12
  ```bash
16
- $ bundle
13
+ bundle add email_error_reporter && bundle install
17
14
  ```
18
15
 
19
- Or install it yourself as:
20
- ```bash
21
- $ gem install email_error_reporter
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"]
22
21
  ```
23
22
 
24
- ## Contributing
25
- Contribution directions go here.
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
+ ## Optional configuration
32
+
33
+ Set a custom from address.
34
+
35
+ ```ruby
36
+ # default: "no-reply@example.com"
37
+ config.email_error_reporter.from = "your-custom-email@example.com"
38
+ ```
39
+
40
+ ## Test your setup
41
+
42
+ You can use the built-in rake task `rake email_error_reporter:check` to check if everything works correctly in your setup.
43
+
44
+ If you're using Kamal, you can run the following command to test the setup in production:
45
+
46
+ ```
47
+ kamal app exec -p 'bundle exec rake email_error_reporter:test_email'
48
+ ```
26
49
 
27
50
  ## License
51
+
28
52
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,3 @@
1
+ <tr>
2
+ <td style="font-family: monospace; padding: 2px;"><%= frame %></td>
3
+ </tr>
@@ -0,0 +1 @@
1
+ <tr><td>No backtrace available</td></tr>
@@ -0,0 +1,22 @@
1
+ <html>
2
+ <body style="max-width: 768px; margin: 0 auto;">
3
+ <h1 style="margin-top: 12px; font-family: sans-serif; font-size: 19px;"><%= @error.class %></h1>
4
+ <h2 style="font-family: sans-serif; font-size: 15px;"><%= @error.message %></h2>
5
+
6
+ <p data-test-id="source">Source: <%= @source ? @source : "No source present" %></p>
7
+ <p data-test-id="handled">Handled: <%= @handled ? "✅" : "❌" %></p>
8
+
9
+ <details style="margin-bottom: 12px;">
10
+ <summary>Stacktrace</summary>
11
+
12
+ <table data-test-id="backtrace" border="1" width="100%" style="margin-top: 12px; margin-bottom: 12px; border-collapse: collapse; border-color: #000000">
13
+ <%= render(partial: "frame", collection: @backtrace) || render("no_backtrace") -%>
14
+ </table>
15
+ </details>
16
+
17
+ <details>
18
+ <summary>Context</summary>
19
+ <pre data-test-id="context" style="font-family: mono; background: #eeeeee;"><code><%= @context %></code></pre>
20
+ </details>
21
+ </body>
22
+ </html>
@@ -0,0 +1,18 @@
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
+ config.email_error_reporter.from = "no-reply@example.com"
8
+
9
+ initializer "email_error_reporter.error_subscribe" do
10
+ Rails.error.subscribe(Subscriber.new)
11
+ end
12
+
13
+ # ActiveJob cannot (de)-serialize exceptions by default
14
+ initializer "email_error_reporter.exception_serializer" do |app|
15
+ app.config.active_job.custom_serializers << ExceptionSerializer
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,25 @@
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
+ severity_to_emoji = {
13
+ error: "🔥",
14
+ warning: "⚠️",
15
+ info: "ℹ️"
16
+ }
17
+
18
+ mail(
19
+ subject: "#{severity_to_emoji.fetch(@severity)} #{error.class}",
20
+ from: Rails.application.config.email_error_reporter.from,
21
+ to: Rails.application.config.email_error_reporter.to
22
+ )
23
+ end
24
+ end
25
+ 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
@@ -1,3 +1,3 @@
1
1
  module EmailErrorReporter
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -1,6 +1,10 @@
1
1
  require "email_error_reporter/version"
2
- require "email_error_reporter/railtie"
2
+ require "email_error_reporter/engine"
3
3
 
4
4
  module EmailErrorReporter
5
- # Your code goes here...
5
+ extend ActiveSupport::Autoload
6
+
7
+ autoload :ErrorMailer
8
+ autoload :Subscriber
9
+ autoload :ExceptionSerializer
6
10
  end
@@ -1,4 +1,12 @@
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
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: email_error_reporter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Niklas Haeusele
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-01-02 00:00:00.000000000 Z
11
+ date: 2024-01-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 7.1.2
19
+ version: 7.0.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 7.1.2
26
+ version: 7.0.0
27
27
  description: Report your Rails errors via email.
28
28
  email:
29
29
  - niklas.haeusele@hey.com
@@ -34,8 +34,14 @@ files:
34
34
  - MIT-LICENSE
35
35
  - README.md
36
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
37
40
  - lib/email_error_reporter.rb
38
- - lib/email_error_reporter/railtie.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
39
45
  - lib/email_error_reporter/version.rb
40
46
  - lib/tasks/email_error_reporter_tasks.rake
41
47
  homepage: https://github.com/codergeek121/email_error_reporter
@@ -53,7 +59,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
53
59
  requirements:
54
60
  - - ">="
55
61
  - !ruby/object:Gem::Version
56
- version: '0'
62
+ version: 3.1.0
57
63
  required_rubygems_version: !ruby/object:Gem::Requirement
58
64
  requirements:
59
65
  - - ">="
@@ -1,4 +0,0 @@
1
- module EmailErrorReporter
2
- class Railtie < ::Rails::Railtie
3
- end
4
- end