exception_notification 4.4.0 → 4.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +5 -5
  2. data/Appraisals +3 -1
  3. data/CHANGELOG.rdoc +33 -0
  4. data/Gemfile +2 -0
  5. data/README.md +36 -13
  6. data/Rakefile +2 -0
  7. data/examples/sample_app.rb +2 -0
  8. data/examples/sinatra/Gemfile +2 -0
  9. data/examples/sinatra/config.ru +2 -0
  10. data/examples/sinatra/sinatra_app.rb +6 -2
  11. data/exception_notification.gemspec +13 -12
  12. data/gemfiles/rails5_2.gemfile +3 -3
  13. data/gemfiles/rails6_1.gemfile +7 -0
  14. data/gemfiles/rails7_0.gemfile +7 -0
  15. data/lib/exception_notification/rack.rb +24 -13
  16. data/lib/exception_notification/rails.rb +2 -0
  17. data/lib/exception_notification/resque.rb +2 -0
  18. data/lib/exception_notification/sidekiq.rb +5 -3
  19. data/lib/exception_notification/version.rb +3 -1
  20. data/lib/exception_notification.rb +2 -0
  21. data/lib/exception_notifier/base_notifier.rb +8 -2
  22. data/lib/exception_notifier/datadog_notifier.rb +12 -9
  23. data/lib/exception_notifier/email_notifier.rb +10 -2
  24. data/lib/exception_notifier/google_chat_notifier.rb +2 -0
  25. data/lib/exception_notifier/hipchat_notifier.rb +2 -0
  26. data/lib/exception_notifier/irc_notifier.rb +4 -3
  27. data/lib/exception_notifier/mattermost_notifier.rb +10 -0
  28. data/lib/exception_notifier/modules/backtrace_cleaner.rb +2 -0
  29. data/lib/exception_notifier/modules/error_grouping.rb +20 -9
  30. data/lib/exception_notifier/modules/formatter.rb +8 -1
  31. data/lib/exception_notifier/notifier.rb +5 -1
  32. data/lib/exception_notifier/slack_notifier.rb +2 -0
  33. data/lib/exception_notifier/sns_notifier.rb +7 -3
  34. data/lib/exception_notifier/teams_notifier.rb +10 -3
  35. data/lib/exception_notifier/webhook_notifier.rb +3 -3
  36. data/lib/exception_notifier.rb +46 -8
  37. data/lib/generators/exception_notification/install_generator.rb +8 -2
  38. data/test/exception_notification/rack_test.rb +48 -2
  39. data/test/exception_notification/resque_test.rb +2 -0
  40. data/test/exception_notifier/datadog_notifier_test.rb +2 -0
  41. data/test/exception_notifier/email_notifier_test.rb +11 -5
  42. data/test/exception_notifier/google_chat_notifier_test.rb +15 -11
  43. data/test/exception_notifier/hipchat_notifier_test.rb +8 -2
  44. data/test/exception_notifier/irc_notifier_test.rb +2 -0
  45. data/test/exception_notifier/mattermost_notifier_test.rb +73 -24
  46. data/test/exception_notifier/modules/error_grouping_test.rb +2 -0
  47. data/test/exception_notifier/modules/formatter_test.rb +2 -0
  48. data/test/exception_notifier/sidekiq_test.rb +3 -11
  49. data/test/exception_notifier/slack_notifier_test.rb +12 -10
  50. data/test/exception_notifier/sns_notifier_test.rb +64 -7
  51. data/test/exception_notifier/teams_notifier_test.rb +2 -0
  52. data/test/exception_notifier/webhook_notifier_test.rb +6 -4
  53. data/test/exception_notifier_test.rb +112 -6
  54. data/test/support/exception_notifier_helper.rb +14 -0
  55. data/test/test_helper.rb +5 -1
  56. metadata +45 -56
  57. data/gemfiles/rails4_0.gemfile +0 -7
  58. data/gemfiles/rails4_1.gemfile +0 -7
  59. data/gemfiles/rails4_2.gemfile +0 -7
  60. data/gemfiles/rails5_0.gemfile +0 -7
  61. data/gemfiles/rails5_1.gemfile +0 -7
  62. data/lib/exception_notifier/campfire_notifier.rb +0 -39
  63. data/test/exception_notifier/campfire_notifier_test.rb +0 -120
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: f61027914f50eed12ef3c115cca8ba7a3f4f3b1e
4
- data.tar.gz: 1a63465348250221f3a7d2171979a8d6b35639c1
2
+ SHA256:
3
+ metadata.gz: f671fa31cec6dbf437c5e31ab10136a00f3ef5450fc13d9de2887296390451ba
4
+ data.tar.gz: 20f146f16e31e91c456cb08f5598b2714dec47ef1efc41741c7cfea761a8176f
5
5
  SHA512:
6
- metadata.gz: 62cf62e3500f7edb53940bbe458a5b2e1936469033c4c643ad47d4ac9d3a913bd406fb7ca37cbf0d27b4f862b5487bd5736abdd37288aaaa904a125a00bd72bf
7
- data.tar.gz: 0ffc513a9fd0ce553254665abfb6da9640a4e9eb3ff5edf39aa838b9baa3caffffd76f0ffab64417721cd7c4828fdabba8c6ab9c9f47077f800845418c38db52
6
+ metadata.gz: a3c4f84bef2faccc2a66306349b983843a1542895d13e8cb141e50e8c610dc525087f8f86fc4c40654140e128c5378b224851c888086b0b32a6cb4753011717e
7
+ data.tar.gz: 5aa30cabeb47f39f89d13c904bdd36da33bf7a598cdb24f14ff6882e90826e3985b1bfb19c55a250bdfc3edae343ec56a72887a5bdbd195bbe4251738a65d1b2
data/Appraisals CHANGED
@@ -1,4 +1,6 @@
1
- rails_versions = ['~> 4.0.5', '~> 4.1.1', '~> 4.2.0', '~> 5.0.0', '~> 5.1.0', '~> 5.2.0']
1
+ # frozen_string_literal: true
2
+
3
+ rails_versions = ['~> 5.2.0', '~> 6.0.0', '~> 6.1.0', '~> 7.0.0']
2
4
 
3
5
  rails_versions.each do |rails_version|
4
6
  appraise "rails#{rails_version.slice(/\d+\.\d+/).tr('.', '_')}" do
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,36 @@
1
+ == 4.5.0
2
+
3
+ * enhancements
4
+ * Added Rails 7 compatibility (by @fwininger)
5
+ * Added support for the optional `data` attribute to the SNS notifier (@TomK32)
6
+ * Addressed a deprecation warning for `module_parent_name` which was thrown for users
7
+ using Rails > 6.x (@quorak)
8
+ * Restored the hash separator for `controller#action` in the email notifier (@garethrees)
9
+
10
+ * removals
11
+ * Dropped support for Tinder (gem is no longer maintained) (by @fwininger)
12
+ * Dropped support for Ruby on Rails versions below 5.2
13
+
14
+ == 4.4.3
15
+
16
+ * big fixes
17
+ * Remove using configured default from address from custom mailer_parent class
18
+
19
+ == 4.4.2 (yanked)
20
+
21
+ * bug fixes
22
+ * Fix `sender_address` being overwritten
23
+
24
+ == 4.4.1
25
+
26
+ * enhancements
27
+ * Enhance `ignore_if` option to allow by-notifier customization (by @fursich)
28
+ * Ignore extended modules of ignored exceptions (by @elengine)
29
+ * Add `exception_data` to Mattermost notifier (by @camillof)
30
+
31
+ * bug fixes
32
+ * Fix Rubocop offenses (by @nicolasferraro)
33
+
1
34
  == 4.4.0
2
35
 
3
36
  * enhancements
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  gemspec
data/README.md CHANGED
@@ -1,15 +1,15 @@
1
1
  # Exception Notification
2
2
 
3
- [![Gem Version](https://fury-badge.herokuapp.com/rb/exception_notification.png)](http://badge.fury.io/rb/exception_notification)
4
- [![Travis](https://api.travis-ci.org/smartinez87/exception_notification.png)](http://travis-ci.org/smartinez87/exception_notification)
5
- [![Coverage Status](https://coveralls.io/repos/smartinez87/exception_notification/badge.png?branch=master)](https://coveralls.io/r/smartinez87/exception_notification)
6
- [![Code Climate](https://codeclimate.com/github/smartinez87/exception_notification.png)](https://codeclimate.com/github/smartinez87/exception_notification)
3
+ [![Gem Version](https://badge.fury.io/rb/exception_notification.svg)](https://badge.fury.io/rb/exception_notification)
4
+ [![Build Status](https://github.com/smartinez87/exception_notification/actions/workflows/main.yml/badge.svg)](https://github.com/smartinez87/exception_notification/actions/workflows/main.yml)
5
+ [![Coverage Status](https://coveralls.io/repos/github/smartinez87/exception_notification/badge.svg?branch=master)](https://coveralls.io/github/smartinez87/exception_notification?branch=master)
6
+ [![Maintainability](https://api.codeclimate.com/v1/badges/78a9a12be00a6d305136/maintainability)](https://codeclimate.com/github/smartinez87/exception_notification/maintainability)
7
7
 
8
8
  **THIS README IS FOR THE MASTER BRANCH AND REFLECTS THE WORK CURRENTLY EXISTING ON THE MASTER BRANCH. IF YOU ARE WISHING TO USE A NON-MASTER BRANCH OF EXCEPTION NOTIFICATION, PLEASE CONSULT THAT BRANCH'S README AND NOT THIS ONE.**
9
9
 
10
10
  ---
11
11
 
12
- The Exception Notification gem provides a set of [notifiers](#notifiers) for sending notifications when errors occur in a Rack/Rails application. The built-in notifiers can deliver notifications by [email](docs/notifiers/email.md), [Campfire](docs/notifiers/campfire.md), [HipChat](docs/notifiers/hipchat.md), [Slack](docs/notifiers/slack.md), [Mattermost](docs/notifiers/mattermost.md), [Teams](docs/notifiers/teams.md), [IRC](docs/notifiers/irc.md), [Amazon SNS](docs/notifiers/sns.md), [Google Chat](docs/notifiers/google_chat.md), [Datadog](docs/notifiers/datadog.md) or via custom [WebHooks](docs/notifiers/webhook.md).
12
+ The Exception Notification gem provides a set of [notifiers](#notifiers) for sending notifications when errors occur in a Rack/Rails application. The built-in notifiers can deliver notifications by [email](docs/notifiers/email.md), [HipChat](docs/notifiers/hipchat.md), [Slack](docs/notifiers/slack.md), [Mattermost](docs/notifiers/mattermost.md), [Teams](docs/notifiers/teams.md), [IRC](docs/notifiers/irc.md), [Amazon SNS](docs/notifiers/sns.md), [Google Chat](docs/notifiers/google_chat.md), [Datadog](docs/notifiers/datadog.md) or via custom [WebHooks](docs/notifiers/webhook.md).
13
13
 
14
14
  There's a great [Railscast about Exception Notification](http://railscasts.com/episodes/104-exception-notifications-revised) you can see that may help you getting started.
15
15
 
@@ -17,10 +17,8 @@ There's a great [Railscast about Exception Notification](http://railscasts.com/e
17
17
 
18
18
  ## Requirements
19
19
 
20
- * Ruby 2.0 or greater
21
- * Rails 4.0 or greater, Sinatra or another Rack-based application.
22
-
23
- For previous releases, please checkout [this](#versions).
20
+ * Ruby 2.5 or greater
21
+ * Rails 5.2 or greater, Sinatra or another Rack-based application.
24
22
 
25
23
  ## Getting Started
26
24
 
@@ -37,7 +35,6 @@ ExceptionNotification is used as a rack middleware, or in the environment you wa
37
35
  ```ruby
38
36
  Rails.application.config.middleware.use ExceptionNotification::Rack,
39
37
  email: {
40
- deliver_with: :deliver, # Rails >= 4.2.1 do not need this option since it defaults to :deliver_now
41
38
  email_prefix: '[PREFIX] ',
42
39
  sender_address: %{"notifier" <notifier@example.com>},
43
40
  exception_recipients: %w{exceptions@example.com}
@@ -86,7 +83,6 @@ Options -> sections" below.
86
83
 
87
84
  ExceptionNotification relies on notifiers to deliver notifications when errors occur in your applications. By default, 8 notifiers are available:
88
85
 
89
- * [Campfire notifier](docs/notifiers/campfire.md)
90
86
  * [Datadog notifier](docs/notifiers/datadog.md)
91
87
  * [Email notifier](docs/notifiers/email.md)
92
88
  * [HipChat notifier](docs/notifiers/hipchat.md)
@@ -138,6 +134,8 @@ You can choose to ignore certain exceptions, which will make ExceptionNotificati
138
134
 
139
135
  * `:ignore_if` - Custom (i.e. ignore exceptions that satisfy some condition)
140
136
 
137
+ * `:ignore_notifer_if` - Custom (i.e. let each notifier ignore exceptions if by-notifier condition is satisfied)
138
+
141
139
 
142
140
  ### :ignore_exceptions
143
141
 
@@ -177,7 +175,7 @@ Rails.application.config.middleware.use ExceptionNotification::Rack,
177
175
 
178
176
  *Lambda, default: nil*
179
177
 
180
- Last but not least, you can ignore exceptions based on a condition. Take a look:
178
+ You can ignore exceptions based on a condition. Take a look:
181
179
 
182
180
  ```ruby
183
181
  Rails.application.config.middleware.use ExceptionNotification::Rack,
@@ -191,6 +189,32 @@ Rails.application.config.middleware.use ExceptionNotification::Rack,
191
189
 
192
190
  You can make use of both the environment and the exception inside the lambda to decide wether to avoid or not sending the notification.
193
191
 
192
+ ### :ignore_notifier_if
193
+
194
+ * Hash of Lambda, default: nil*
195
+
196
+ In case you want a notifier to ignore certain exceptions, but don't want other notifiers to skip them, you can set by-notifier ignore options.
197
+ By setting below, each notifier will ignore exceptions when its corresponding condition is met.
198
+
199
+ ```ruby
200
+ Rails.application.config.middleware.use ExceptionNotification::Rack,
201
+ ignore_notifier_if: {
202
+ email: ->(env, exception) { !Rails.env.production? },
203
+ slack: ->(env, exception) { exception.message =~ /^Couldn't find Page with ID=/ }
204
+ }
205
+
206
+ email: {
207
+ sender_address: %{"notifier" <notifier@example.com>},
208
+ exception_recipients: %w{exceptions@example.com}
209
+ },
210
+ slack: {
211
+ webhook_url: '[Your webhook url]',
212
+ channel: '#exceptions',
213
+ }
214
+ ```
215
+
216
+ To customize each condition, you can make use of environment and the exception object inside the lambda.
217
+
194
218
  ## Rack X-Cascade Header
195
219
 
196
220
  Some rack apps (Rails in particular) utilize the "X-Cascade" header to pass the request-handling responsibility to the next middleware in the stack.
@@ -245,7 +269,6 @@ def server_error(exception)
245
269
  end
246
270
  ```
247
271
 
248
-
249
272
  ## Extras
250
273
 
251
274
  ### Rails
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rubygems'
2
4
  require 'bundler/setup'
3
5
  Bundler::GemHelper.install_tasks
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # -------------------------------------------
2
4
  # To run the application: ruby examples/sample_app.rb
3
5
  # -------------------------------------------
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  gem 'exception_notification', path: '../../'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require ::File.expand_path('../sinatra_app', __FILE__)
2
4
 
3
5
  run SinatraApp
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rubygems'
2
4
  require 'bundler/setup'
3
5
  require 'sinatra/base'
@@ -5,7 +7,8 @@ require 'exception_notification'
5
7
 
6
8
  class SinatraApp < Sinatra::Base
7
9
  use Rack::Config do |env|
8
- env['action_dispatch.parameter_filter'] = [:password] # This is highly recommended. It will prevent the ExceptionNotification email from including your users' passwords
10
+ # This is highly recommended. It will prevent the ExceptionNotification email from including your users' passwords
11
+ env['action_dispatch.parameter_filter'] = [:password]
9
12
  end
10
13
 
11
14
  use ExceptionNotification::Rack,
@@ -22,7 +25,8 @@ class SinatraApp < Sinatra::Base
22
25
  get '/' do
23
26
  raise StandardError, "ERROR: #{params[:error]}" unless params[:error].blank?
24
27
 
25
- 'Everything is fine! Now, lets break things clicking <a href="/?error=ops"> here </a>. Dont forget to see the emails at <a href="http://localhost:1080">mailcatcher</a> !'
28
+ 'Everything is fine! Now, lets break things clicking <a href="/?error=ops"> here </a>.' \
29
+ 'Dont forget to see the emails at <a href="http://localhost:1080">mailcatcher</a> !'
26
30
  end
27
31
 
28
32
  get '/background_notification' do
@@ -1,16 +1,18 @@
1
- require File.expand_path('../lib/exception_notification/version', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ require File.expand_path('lib/exception_notification/version', __dir__)
2
4
 
3
5
  Gem::Specification.new do |s|
4
6
  s.name = 'exception_notification'
5
7
  s.version = ExceptionNotification::VERSION
6
8
  s.authors = ['Jamis Buck', 'Josh Peek']
7
- s.date = '2019-08-16'
9
+ s.date = '2022-01-20'
8
10
  s.summary = 'Exception notification for Rails apps'
9
11
  s.homepage = 'https://smartinez87.github.io/exception_notification/'
10
12
  s.email = 'smartinez87@gmail.com'
11
13
  s.license = 'MIT'
12
14
 
13
- s.required_ruby_version = '>= 2.0'
15
+ s.required_ruby_version = '>= 2.3'
14
16
  s.required_rubygems_version = '>= 1.8.11'
15
17
 
16
18
  s.files = `git ls-files`.split("\n")
@@ -18,8 +20,8 @@ Gem::Specification.new do |s|
18
20
  s.test_files = `git ls-files -- test`.split("\n")
19
21
  s.require_path = 'lib'
20
22
 
21
- s.add_dependency('actionmailer', '>= 4.0', '< 7')
22
- s.add_dependency('activesupport', '>= 4.0', '< 7')
23
+ s.add_dependency('actionmailer', '>= 5.2', '< 8')
24
+ s.add_dependency('activesupport', '>= 5.2', '< 8')
23
25
 
24
26
  s.add_development_dependency 'appraisal', '~> 2.2.0'
25
27
  s.add_development_dependency 'aws-sdk-sns', '~> 1'
@@ -28,14 +30,13 @@ Gem::Specification.new do |s|
28
30
  s.add_development_dependency 'dogapi', '>= 1.23.0'
29
31
  s.add_development_dependency 'hipchat', '>= 1.0.0'
30
32
  s.add_development_dependency 'httparty', '~> 0.10.2'
31
- s.add_development_dependency 'mock_redis', '~> 0.18.0'
32
33
  s.add_development_dependency 'mocha', '>= 0.13.0'
33
- s.add_development_dependency 'rails', '>= 4.0', '< 7'
34
+ s.add_development_dependency 'mock_redis', '~> 0.19.0'
35
+ s.add_development_dependency 'net-smtp'
36
+ s.add_development_dependency 'rails', '>= 5.2', '< 8'
34
37
  s.add_development_dependency 'resque', '~> 1.8.0'
35
- s.add_development_dependency 'rubocop', '0.50.0'
36
- # Sidekiq 3.2.2 does not support Ruby 1.9.
37
- s.add_development_dependency 'sidekiq', '~> 3.0.0', '< 3.2.2'
38
+ s.add_development_dependency 'rubocop', '0.78.0'
39
+ s.add_development_dependency 'sidekiq', '>= 5.0.4'
38
40
  s.add_development_dependency 'slack-notifier', '>= 1.0.0'
39
- s.add_development_dependency 'timecop', '~>0.9.0'
40
- s.add_development_dependency 'tinder', '~> 1.8'
41
+ s.add_development_dependency 'timecop', '~> 0.9.0'
41
42
  end
@@ -1,7 +1,7 @@
1
1
  # This file was generated by Appraisal
2
2
 
3
- source 'https://rubygems.org'
3
+ source "https://rubygems.org"
4
4
 
5
- gem 'rails', '~> 5.2.0'
5
+ gem "rails", "~> 5.2.0"
6
6
 
7
- gemspec path: '../'
7
+ gemspec path: "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 6.1.0"
6
+
7
+ gemspec path: "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 7.0.0"
6
+
7
+ gemspec path: "../"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ExceptionNotification
2
4
  class Rack
3
5
  class CascadePassException < RuntimeError; end
@@ -5,15 +7,17 @@ module ExceptionNotification
5
7
  def initialize(app, options = {})
6
8
  @app = app
7
9
 
8
- ExceptionNotifier.ignored_exceptions = options.delete(:ignore_exceptions) if options.key?(:ignore_exceptions)
9
- ExceptionNotifier.error_grouping = options.delete(:error_grouping) if options.key?(:error_grouping)
10
- ExceptionNotifier.error_grouping_period = options.delete(:error_grouping_period) if options.key?(:error_grouping_period)
11
- ExceptionNotifier.notification_trigger = options.delete(:notification_trigger) if options.key?(:notification_trigger)
10
+ ExceptionNotifier.tap do |en|
11
+ en.ignored_exceptions = options.delete(:ignore_exceptions) if options.key?(:ignore_exceptions)
12
+ en.error_grouping = options.delete(:error_grouping) if options.key?(:error_grouping)
13
+ en.error_grouping_period = options.delete(:error_grouping_period) if options.key?(:error_grouping_period)
14
+ en.notification_trigger = options.delete(:notification_trigger) if options.key?(:notification_trigger)
12
15
 
13
- if options.key?(:error_grouping_cache)
14
- ExceptionNotifier.error_grouping_cache = options.delete(:error_grouping_cache)
15
- elsif defined?(Rails) && Rails.respond_to?(:cache)
16
- ExceptionNotifier.error_grouping_cache = Rails.cache
16
+ if options.key?(:error_grouping_cache)
17
+ en.error_grouping_cache = options.delete(:error_grouping_cache)
18
+ elsif defined?(Rails) && Rails.respond_to?(:cache)
19
+ en.error_grouping_cache = Rails.cache
20
+ end
17
21
  end
18
22
 
19
23
  if options.key?(:ignore_if)
@@ -23,6 +27,15 @@ module ExceptionNotification
23
27
  end
24
28
  end
25
29
 
30
+ if options.key?(:ignore_notifier_if)
31
+ rack_ignore_by_notifier = options.delete(:ignore_notifier_if)
32
+ rack_ignore_by_notifier.each do |notifier, proc|
33
+ ExceptionNotifier.ignore_notifier_if(notifier) do |exception, opts|
34
+ opts.key?(:env) && proc.call(opts[:env], exception)
35
+ end
36
+ end
37
+ end
38
+
26
39
  ExceptionNotifier.ignore_crawlers(options.delete(:ignore_crawlers)) if options.key?(:ignore_crawlers)
27
40
 
28
41
  @ignore_cascade_pass = options.delete(:ignore_cascade_pass) { true }
@@ -42,12 +55,10 @@ module ExceptionNotification
42
55
  end
43
56
 
44
57
  response
45
- rescue Exception => exception
46
- if ExceptionNotifier.notify_exception(exception, env: env)
47
- env['exception_notifier.delivered'] = true
48
- end
58
+ rescue Exception => e
59
+ env['exception_notifier.delivered'] = true if ExceptionNotifier.notify_exception(e, env: env)
49
60
 
50
- raise exception unless exception.is_a?(CascadePassException)
61
+ raise e unless e.is_a?(CascadePassException)
51
62
 
52
63
  response
53
64
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ExceptionNotification
2
4
  class Engine < ::Rails::Engine
3
5
  config.exception_notification = ExceptionNotifier
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'resque/failure/base'
2
4
 
3
5
  module ExceptionNotification
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'sidekiq'
2
4
 
3
5
  # Note: this class is only needed for Sidekiq version < 3.
@@ -5,9 +7,9 @@ module ExceptionNotification
5
7
  class Sidekiq
6
8
  def call(_worker, msg, _queue)
7
9
  yield
8
- rescue Exception => exception
9
- ExceptionNotifier.notify_exception(exception, data: { sidekiq: msg })
10
- raise exception
10
+ rescue Exception => e
11
+ ExceptionNotifier.notify_exception(e, data: { sidekiq: msg })
12
+ raise e
11
13
  end
12
14
  end
13
15
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ExceptionNotification
2
- VERSION = '4.4.0'.freeze
4
+ VERSION = '4.5.0'
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'exception_notifier'
2
4
  require 'exception_notification/rack'
3
5
  require 'exception_notification/version'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ExceptionNotifier
2
4
  class BaseNotifier
3
5
  attr_accessor :base_options
@@ -14,11 +16,15 @@ module ExceptionNotifier
14
16
  end
15
17
 
16
18
  def _pre_callback(exception, options, message, message_opts)
17
- @base_options[:pre_callback].call(options, self, exception.backtrace, message, message_opts) if @base_options[:pre_callback].respond_to?(:call)
19
+ return unless @base_options[:pre_callback].respond_to?(:call)
20
+
21
+ @base_options[:pre_callback].call(options, self, exception.backtrace, message, message_opts)
18
22
  end
19
23
 
20
24
  def _post_callback(exception, options, message, message_opts)
21
- @base_options[:post_callback].call(options, self, exception.backtrace, message, message_opts) if @base_options[:post_callback].respond_to?(:call)
25
+ return unless @base_options[:post_callback].respond_to?(:call)
26
+
27
+ @base_options[:post_callback].call(options, self, exception.backtrace, message, message_opts)
22
28
  end
23
29
  end
24
30
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'action_dispatch'
2
4
 
3
5
  module ExceptionNotifier
@@ -30,7 +32,7 @@ module ExceptionNotifier
30
32
  MAX_TITLE_LENGTH = 120
31
33
  MAX_VALUE_LENGTH = 300
32
34
  MAX_BACKTRACE_SIZE = 3
33
- ALERT_TYPE = 'error'.freeze
35
+ ALERT_TYPE = 'error'
34
36
 
35
37
  attr_reader :exception,
36
38
  :options
@@ -74,11 +76,8 @@ module ExceptionNotifier
74
76
  end
75
77
 
76
78
  def formatted_title
77
- title = ''
78
- title << title_prefix
79
- title << "#{controller.controller_name} #{controller.action_name}" if controller
80
- title << " (#{exception.class})"
81
- title << " #{exception.message.inspect}"
79
+ title =
80
+ "#{title_prefix}#{controller_subtitle} (#{exception.class}) #{exception.message.inspect}"
82
81
 
83
82
  truncate(title, MAX_TITLE_LENGTH)
84
83
  end
@@ -108,9 +107,7 @@ module ExceptionNotifier
108
107
  text << formatted_key_value('Parameters', request.filtered_parameters.inspect)
109
108
  text << formatted_key_value('Timestamp', Time.current)
110
109
  text << formatted_key_value('Server', Socket.gethostname)
111
- if defined?(Rails) && Rails.respond_to?(:root)
112
- text << formatted_key_value('Rails root', Rails.root)
113
- end
110
+ text << formatted_key_value('Rails root', Rails.root) if defined?(Rails) && Rails.respond_to?(:root)
114
111
  text << formatted_key_value('Process', $PROCESS_ID)
115
112
  text << '___'
116
113
  text.join("\n")
@@ -148,6 +145,12 @@ module ExceptionNotifier
148
145
  object.to_s
149
146
  end
150
147
  end
148
+
149
+ private
150
+
151
+ def controller_subtitle
152
+ "#{controller.controller_name} #{controller.action_name}" if controller
153
+ end
151
154
  end
152
155
  end
153
156
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'active_support/core_ext/time'
2
4
  require 'action_mailer'
3
5
  require 'action_dispatch'
@@ -74,13 +76,17 @@ module ExceptionNotifier
74
76
  def compose_subject
75
77
  subject = @options[:email_prefix].to_s.dup
76
78
  subject << "(#{@options[:accumulated_errors_count]} times)" if @options[:accumulated_errors_count].to_i > 1
77
- subject << "#{@kontroller.controller_name} #{@kontroller.action_name}" if @kontroller && @options[:include_controller_and_action_names_in_subject]
79
+ subject << "#{@kontroller.controller_name}##{@kontroller.action_name}" if include_controller?
78
80
  subject << " (#{@exception.class})"
79
81
  subject << " #{@exception.message.inspect}" if @options[:verbose_subject]
80
82
  subject = EmailNotifier.normalize_digits(subject) if @options[:normalize_subject]
81
83
  subject.length > 120 ? subject[0...120] + '...' : subject
82
84
  end
83
85
 
86
+ def include_controller?
87
+ @kontroller && @options[:include_controller_and_action_names_in_subject]
88
+ end
89
+
84
90
  def set_data_variables
85
91
  @data.each do |name, value|
86
92
  instance_variable_set("@#{name}", value)
@@ -137,7 +143,9 @@ module ExceptionNotifier
137
143
  end
138
144
 
139
145
  def load_custom_views
140
- prepend_view_path Rails.root.nil? ? 'app/views' : "#{Rails.root}/app/views" if defined?(Rails) && Rails.respond_to?(:root)
146
+ return unless defined?(Rails) && Rails.respond_to?(:root)
147
+
148
+ prepend_view_path Rails.root.nil? ? 'app/views' : "#{Rails.root}/app/views"
141
149
  end
142
150
 
143
151
  def maybe_call(maybe_proc)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'httparty'
2
4
 
3
5
  module ExceptionNotifier
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ExceptionNotifier
2
4
  class HipchatNotifier < BaseNotifier
3
5
  attr_accessor :from
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ExceptionNotifier
2
4
  class IrcNotifier < BaseNotifier
3
5
  def initialize(options)
@@ -9,9 +11,8 @@ module ExceptionNotifier
9
11
  def call(exception, options = {})
10
12
  errors_count = options[:accumulated_errors_count].to_i
11
13
 
12
- message = "'#{exception.message}'"
13
- message.prepend("(#{errors_count} times)") if errors_count > 1
14
-
14
+ occurrences = "(#{errors_count} times)" if errors_count > 1
15
+ message = "#{occurrences}'#{exception.message}'"
15
16
  message += " on '#{exception.backtrace.first}'" if exception.backtrace
16
17
 
17
18
  return unless active?
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'httparty'
2
4
 
3
5
  module ExceptionNotifier
@@ -10,6 +12,8 @@ module ExceptionNotifier
10
12
 
11
13
  @gitlab_url = options[:git_url]
12
14
 
15
+ @env = options[:env] || {}
16
+
13
17
  payload = {
14
18
  text: message_text.compact.join("\n"),
15
19
  username: options[:username] || 'Exception Notifier'
@@ -52,6 +56,12 @@ module ExceptionNotifier
52
56
  text << backtrace
53
57
  end
54
58
 
59
+ if (exception_data = @env['exception_notifier.exception_data'])
60
+ text << '### Data'
61
+ data_string = exception_data.map { |k, v| "* #{k} : #{v}" }.join("\n")
62
+ text << "```\n#{data_string}\n```"
63
+ end
64
+
55
65
  text << message_issue_link if @gitlab_url
56
66
 
57
67
  text
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ExceptionNotifier
2
4
  module BacktraceCleaner
3
5
  def clean_backtrace(exception)