pboling-super_exception_notifier 1.6.7 → 1.6.8

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.
@@ -23,6 +23,8 @@ New features:
23
23
  * get error notification for errors that occur in the console, using notifiable method
24
24
  * Hooks into `git blame` output so you can get an idea of who (may) have introduced the bug
25
25
  * Hooks into other website services (e.g. you can send exceptions to to Switchub.com)
26
+ * Specify which level of notification you would like with an array of optional styles of notification:
27
+ [:render, :email, :web_hooks]
26
28
 
27
29
  The email includes information about the current request, session, and
28
30
  environment, and also gives a backtrace of the exception.
@@ -54,7 +56,7 @@ Gem Using Git building from source:
54
56
  git clone git://github.com/pboling/exception_notification.git
55
57
  cd exception_notification
56
58
  gem build exception_notification.gemspec
57
- sudo gem install super_exception_notification-1.6.7.gem # (Or whatever version gets built)
59
+ sudo gem install super_exception_notification-1.6.8.gem # (Or whatever version gets built)
58
60
 
59
61
  Then cd to your rails app to optionally freeze the gem into your app:
60
62
 
@@ -63,7 +65,7 @@ Then cd to your rails app to optionally freeze the gem into your app:
63
65
  Then in your environment.rb:
64
66
 
65
67
  config.gem 'super_exception_notifier',
66
- :version => '~> 1.6.7',
68
+ :version => '~> 1.6.8',
67
69
  :lib => "exception_notifier"
68
70
 
69
71
 
@@ -75,7 +77,7 @@ Installing Gem from Github's Gem Server:
75
77
  Then in your environment.rb:
76
78
 
77
79
  config.gem 'pboling-super_exception_notifier',
78
- :version => '~> 1.6.7',
80
+ :version => '~> 1.6.9',
79
81
  :lib => "exception_notifier",
80
82
  :source => 'http://gems.github.com'
81
83
 
@@ -109,8 +111,9 @@ to generate error emails (typically ApplicationController):
109
111
 
110
112
  4. That's it! The defaults take care of the rest.
111
113
 
112
- == Basic Configuration
114
+ == Basic Environment Configuration
113
115
 
116
+ These are settings that are global for SEN wherever it is used in your project.
114
117
  You can tweak other values to your liking, as well. In your environment file,
115
118
  just set any or all of the following values (defaults are shown):
116
119
 
@@ -118,6 +121,8 @@ just set any or all of the following values (defaults are shown):
118
121
  # If left empty web hooks will not be engaged
119
122
  config[:web_hooks] = []
120
123
  config[:app_name] = "[MYAPP]"
124
+ # NOTE: THERE IS A BUG IN RAILS 2.3.3 which forces us to NOT use anything but a simple email address string for the sender address.
125
+ # https://rails.lighthouseapp.com/projects/8994/tickets/2340
121
126
  config[:sender_address] = %("#{(defined?(Rails) ? Rails.env : RAILS_ENV).capitalize} Error" <super.exception.notifier@example.com>)
122
127
  config[:exception_recipients] = []
123
128
  # Customize the subject line
@@ -127,21 +132,95 @@ just set any or all of the following values (defaults are shown):
127
132
  config[:sections] = %w(request session environment backtrace)
128
133
  # Only use this gem to render, never email
129
134
  #defaults to false - meaning by default it sends email. Setting true will cause it to only render the error pages, and NOT email.
130
- config[:render_only] = false
131
- config[:skip_local_notification = true
135
+ config[:skip_local_notification] = true
132
136
  # Example:
133
137
  #config[:view_path] = 'app/views/error'
134
138
  config[:view_path] = nil
135
- #Error Notification will be sent if the HTTP response code for the error matches one of the following error codes
136
- config[:send_email_error_codes] = %W( 405 500 503 )
137
- #Error Notification will be sent if the error class matches one of the following error error classes
138
- config[:send_email_error_classes] = %W( )
139
- config[:send_email_other_errors] = true
139
+ # Error Notification will be sent if the HTTP response code for the error matches one of the following error codes
140
+ config[:notify_error_codes] = %W( 405 500 503 )
141
+ # Error Notification will be sent if the error class matches one of the following error error classes
142
+ config[:notify_error_classes] = %W( )
143
+ # What should we do for errors not listed?
144
+ config[:notify_other_errors] = true
140
145
  # If you set this SEN will
141
146
  config[:git_repo_path] = nil
142
147
  config[:template_root] = "#{File.dirname(__FILE__)}/../views"
143
148
  end
144
149
 
150
+ == Basic Object Configuration
151
+
152
+ In any controller you do this:
153
+ include ExceptionNotifiable
154
+
155
+ Then that controller (or all of them if you put it in the application controller) will have its errors handled by SEN.
156
+ You can customize how each controller handles exceptions on a per controller basis, or all together in the application controller.
157
+ The availalbe configuration options are shown with their default settings:
158
+
159
+ # HTTP status codes and what their 'English' status message is
160
+ self.http_error_codes = {
161
+ "400" => "Bad Request",
162
+ "403" => "Forbidden",
163
+ "404" => "Not Found",
164
+ "405" => "Method Not Allowed",
165
+ "410" => "Gone",
166
+ "418" => "I�m a teapot",
167
+ "422" => "Unprocessable Entity",
168
+ "423" => "Locked",
169
+ "500" => "Internal Server Error",
170
+ "501" => "Not Implemented",
171
+ "503" => "Service Unavailable"
172
+ }
173
+ # error_layout:
174
+ # can be defined at controller level to the name of the desired error layout,
175
+ # or set to true to render the controller's own default layout,
176
+ # or set to false to render errors with no layout
177
+ # syntax is the same as the rails 'layout' method (which is to say a string)
178
+ self.error_layout = nil
179
+ # Rails error classes to rescue and how to rescue them (which error code to use)
180
+ self.rails_error_classes = {
181
+ # These are standard errors in rails / ruby
182
+ NameError => "503",
183
+ TypeError => "503",
184
+ RuntimeError => "500",
185
+ # These are custom error names defined in lib/super_exception_notifier/custom_exception_classes
186
+ AccessDenied => "403",
187
+ PageNotFound => "404",
188
+ InvalidMethod => "405",
189
+ ResourceGone => "410",
190
+ CorruptData => "422",
191
+ NoMethodError => "500",
192
+ NotImplemented => "501",
193
+ MethodDisabled => "200"
194
+ }
195
+ # Highly dependent on the verison of rails, so we're very protective about these'
196
+ self.rails_error_classes.merge!({ ActionView::TemplateError => "500"}) if defined?(ActionView) && ActionView.const_defined?(:TemplateError)
197
+ self.rails_error_classes.merge!({ ActiveRecord::RecordNotFound => "400" }) if defined?(ActiveRecord) && ActiveRecord.const_defined?(:RecordNotFound)
198
+ self.rails_error_classes.merge!({ ActiveResource::ResourceNotFound => "404" }) if defined?(ActiveResource) && ActiveResource.const_defined?(:ResourceNotFound)
199
+
200
+ if defined?(ActionController)
201
+ self.rails_error_classes.merge!({ ActionController::UnknownController => "404" }) if ActionController.const_defined?(:UnknownController)
202
+ self.rails_error_classes.merge!({ ActionController::MissingTemplate => "404" }) if ActionController.const_defined?(:MissingTemplate)
203
+ self.rails_error_classes.merge!({ ActionController::MethodNotAllowed => "405" }) if ActionController.const_defined?(:MethodNotAllowed)
204
+ self.rails_error_classes.merge!({ ActionController::UnknownAction => "501" }) if ActionController.const_defined?(:UnknownAction)
205
+ self.rails_error_classes.merge!({ ActionController::RoutingError => "404" }) if ActionController.const_defined?(:RoutingError)
206
+ self.rails_error_classes.merge!({ ActionController::InvalidAuthenticityToken => "405" }) if ActionController.const_defined?(:InvalidAuthenticityToken)
207
+ end
208
+ # Verbosity of the gem (true or false) mainly useful for debugging
209
+ self.exception_notifier_verbose = false
210
+ # Do Not Ever send error notification emails for these Error Classes
211
+ self.silent_exceptions = []
212
+ self.silent_exceptions << ActiveRecord::RecordNotFound if defined?(ActiveRecord)
213
+ self.silent_exceptions << [
214
+ ActionController::UnknownController,
215
+ ActionController::UnknownAction,
216
+ ActionController::RoutingError,
217
+ ActionController::MethodNotAllowed
218
+ ] if defined?(ActionController)
219
+ # Notification Level
220
+ # Web Hooks, even though they are turned on by default, only get used if you actually configure them in the environment (see above)
221
+ # Email, even though it is turned on by default, only gets used if you actually configure recipients in the environment (see above)
222
+ self.notification_level = [:render, :email, :web_hooks]
223
+
145
224
  == Environmental Behavior
146
225
 
147
226
  Email notifications will only occur when the IP address is determined not to
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 1
3
3
  :minor: 6
4
- :patch: 7
4
+ :patch: 8
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'super_exception_notifier'
3
- s.version = '1.6.7'
4
- s.date = '2009-08-14'
3
+ s.version = '1.6.8'
4
+ s.date = '2009-08-15'
5
5
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
6
6
 
7
7
  s.summary = %q{Allows unhandled (and handled!) exceptions to be captured and sent via email}
@@ -18,7 +18,10 @@ Gem::Specification.new do |s|
18
18
  * custom errors, with custom error templates
19
19
  * define error layouts at application or controller level, or use the controller's own default layout, or no layout at all
20
20
  * get error notification for errors that occur in the console, using notifiable method
21
- * Override the gem's handling and rendering with explicit rescue statements inline.}
21
+ * Override the gem's handling and rendering with explicit rescue statements inline.
22
+ * Hooks into `git blame` output so you can get an idea of who (may) have introduced the bug
23
+ * Hooks into other website services (e.g. you can send exceptions to to Switchub.com)
24
+ * Specify which level of notification you would like with an array of optional styles of notification}
22
25
 
23
26
  s.authors = ['Peter Boling', 'Jacques Crocker', 'Jamis Buck']
24
27
  s.email = 'peter.boling@gmail.com'
@@ -37,6 +37,7 @@ module ExceptionNotifiable
37
37
  NameError => "503",
38
38
  TypeError => "503",
39
39
  RuntimeError => "500",
40
+ ArgumentError => "500",
40
41
  # These are custom error names defined in lib/super_exception_notifier/custom_exception_classes
41
42
  AccessDenied => "403",
42
43
  PageNotFound => "404",
@@ -67,21 +68,26 @@ module ExceptionNotifiable
67
68
 
68
69
  # Adds the following class attributes to the classes that include ExceptionNotifiable
69
70
  # HTTP status codes and what their 'English' status message is
70
- # Rails error classes to rescue and how to rescue them
71
- # error_layout:
72
- # can be defined at controller level to the name of the layout,
73
- # or set to true to render the controller's own default layout,
74
- # or set to false to render errors with no layout
75
71
  base.cattr_accessor :http_error_codes
76
72
  base.http_error_codes = HTTP_ERROR_CODES
73
+ # error_layout:
74
+ # can be defined at controller level to the name of the desired error layout,
75
+ # or set to true to render the controller's own default layout,
76
+ # or set to false to render errors with no layout
77
77
  base.cattr_accessor :error_layout
78
78
  base.error_layout = nil
79
+ # Rails error classes to rescue and how to rescue them (which error code to use)
79
80
  base.cattr_accessor :rails_error_classes
80
81
  base.rails_error_classes = self.codes_for_rails_error_classes
82
+ # Verbosity of the gem
81
83
  base.cattr_accessor :exception_notifier_verbose
82
84
  base.exception_notifier_verbose = false
85
+ # Do Not Ever send error notification emails for these Error Classes
83
86
  base.cattr_accessor :silent_exceptions
84
87
  base.silent_exceptions = SILENT_EXCEPTIONS
88
+ # Notification Level
89
+ base.cattr_accessor :notification_level
90
+ base.notification_level = [:render, :email, :web_hooks]
85
91
  end
86
92
 
87
93
  module ClassMethods
@@ -111,6 +117,16 @@ module ExceptionNotifiable
111
117
 
112
118
  private
113
119
 
120
+ def notification_level_renders?
121
+ self.class.notification_level.include?(:render)
122
+ end
123
+ def notification_level_sends_email?
124
+ self.class.notification_level.include?(:email)
125
+ end
126
+ def notification_level_sends_web_hooks?
127
+ self.class.notification_level.include?(:web_hooks)
128
+ end
129
+
114
130
  # overrides Rails' local_request? method to also check any ip
115
131
  # addresses specified through consider_local.
116
132
  def local_request?
@@ -123,10 +139,13 @@ module ExceptionNotifiable
123
139
  to_return = super
124
140
  if to_return
125
141
  data = get_exception_data
126
- send_email = should_notify_on_exception?(exception)
127
- send_web_hooks = !ExceptionNotifier.config[:web_hooks].empty?
142
+ status_code = status_code_for_exception(exception)
143
+ #We only send email if it has been configured in environment
144
+ send_email = should_email_on_exception?(exception, status_code, self.class.exception_notifier_verbose)
145
+ #We only send web hooks if they've been configured in environment
146
+ send_web_hooks = should_web_hook_on_exception?(exception, status_code, self.class.exception_notifier_verbose)
128
147
  the_blamed = ExceptionNotifier.config[:git_repo_path].nil? ? nil : lay_blame(exception)
129
- verbose_output(exception, "N/A", "rescued by handler", send_email, send_web_hooks, nil, the_blamed) if self.class.exception_notifier_verbose
148
+ verbose_output(exception, status_code, "rescued by handler", send_email, send_web_hooks, nil, the_blamed) if self.class.exception_notifier_verbose
130
149
  # Send the exception notificaiton email
131
150
  perform_exception_notify_mailing(exception, data, nil, the_blamed) if send_email
132
151
  # Send Web Hook requests
@@ -140,23 +159,26 @@ module ExceptionNotifiable
140
159
  # If the error class is NOT listed in the rails_errror_class hash then we get a generic 500 error:
141
160
  # OTW if the error class is listed, but has a blank code or the code is == '200' then we get a custom error layout rendered
142
161
  # OTW the error class is listed!
162
+ verbose = self.class.exception_notifier_verbose
143
163
  status_code = status_code_for_exception(exception)
144
164
  if status_code == '200'
145
- notify_and_render_error_template(status_code, request, exception, ExceptionNotifier.get_view_path_for_class(exception, self.class.exception_notifier_verbose))
165
+ notify_and_render_error_template(status_code, request, exception, ExceptionNotifier.get_view_path_for_class(exception, verbose), verbose)
146
166
  else
147
- notify_and_render_error_template(status_code, request, exception, ExceptionNotifier.get_view_path_for_status_code(status_code, self.class.exception_notifier_verbose))
167
+ notify_and_render_error_template(status_code, request, exception, ExceptionNotifier.get_view_path_for_status_code(status_code, verbose), verbose)
148
168
  end
149
169
  end
150
170
 
151
- def notify_and_render_error_template(status_cd, request, exception, file_path)
171
+ def notify_and_render_error_template(status_cd, request, exception, file_path, verbose = false)
152
172
  status = self.class.http_error_codes[status_cd] ? status_cd + " " + self.class.http_error_codes[status_cd] : status_cd
153
173
  data = get_exception_data
154
- send_email = should_notify_on_exception?(exception, status_cd)
155
- send_web_hooks = !ExceptionNotifier.config[:web_hooks].empty?
174
+ #We only send email if it has been configured in environment
175
+ send_email = should_email_on_exception?(exception, status_cd, verbose)
176
+ #We only send web hooks if they've been configured in environment
177
+ send_web_hooks = should_web_hook_on_exception?(exception, status_cd, verbose)
156
178
  the_blamed = ExceptionNotifier.config[:git_repo_path].nil? ? nil : lay_blame(exception)
157
179
 
158
180
  # Debugging output
159
- verbose_output(exception, status_cd, file_path, send_email, send_web_hooks, request, the_blamed) if self.class.exception_notifier_verbose
181
+ verbose_output(exception, status_cd, file_path, send_email, send_web_hooks, request, the_blamed) if verbose
160
182
  # Send the email before rendering to avert possible errors on render preventing the email from being sent.
161
183
  perform_exception_notify_mailing(exception, data, request, the_blamed) if send_email
162
184
  # Send Web Hook requests
@@ -207,16 +229,28 @@ module ExceptionNotifiable
207
229
  end
208
230
  end
209
231
 
210
- def should_notify_on_exception?(exception, status_cd = nil)
211
- # First honor the custom settings from environment
212
- return false if ExceptionNotifier.config[:render_only]
213
- # don't mail exceptions raised locally
232
+ def should_email_on_exception?(exception, status_cd = nil, verbose = false)
233
+ notification_level_sends_email? && !ExceptionNotifier.config[:exception_recipients].empty? && should_notify_on_exception?(exception, status_cd)
234
+ end
235
+
236
+ def should_web_hook_on_exception?(exception, status_cd = nil, verbose = false)
237
+ notification_level_sends_web_hooks? && !ExceptionNotifier.config[:web_hooks].empty? && should_notify_on_exception?(exception, status_cd)
238
+ end
239
+
240
+ def should_notify_on_exception?(exception, status_cd = nil, verbose = false)
241
+ puts "checking if should notify on exception E:#{exception} C: #{exception} SC: #{status_cd}" if verbose
242
+ # don't notify (email or web hooks) on exceptions raised locally
243
+ puts "skipping local notification" if verbose && ExceptionNotifier.config[:skip_local_notification] && is_local?
214
244
  return false if ExceptionNotifier.config[:skip_local_notification] && is_local?
215
- # don't mail exceptions raised that match ExceptionNotifiable.silent_exceptions
245
+ # don't notify (email or web hooks) exceptions raised that match ExceptionNotifiable.silent_exceptions
246
+ puts "skipping silent exception notification: K:#{klass} E:#{exception} C:#{exception.class}" if verbose && self.class.silent_exceptions.any? {|klass| klass === exception }
216
247
  return false if self.class.silent_exceptions.any? {|klass| klass === exception }
217
- return true if ExceptionNotifier.config[:send_email_error_classes].include?(exception)
218
- return true if !status_cd.nil? && ExceptionNotifier.config[:send_email_error_codes].include?(status_cd)
219
- return ExceptionNotifier.config[:send_email_other_errors]
248
+ puts "notifying for: E:#{exception} C:#{exception.class}" if verbose && ExceptionNotifier.config[:notify_error_classes].include?(exception)
249
+ return true if ExceptionNotifier.config[:notify_error_classes].include?(exception)
250
+ puts "notifying for status code: #{status_cd}" if verbose && !status_cd.nil? && ExceptionNotifier.config[:notify_error_codes].include?(status_cd)
251
+ return true if !status_cd.nil? && ExceptionNotifier.config[:notify_error_codes].include?(status_cd)
252
+ puts "Notify [#{ExceptionNotifier.config[:notify_other_errors] ? "YES" : "NO"}] Other Error: status code: #{status_cd} E:#{exception} C:#{exception.class}" if verbose
253
+ return ExceptionNotifier.config[:notify_other_errors]
220
254
  end
221
255
 
222
256
  def is_local?
@@ -2,7 +2,8 @@ require 'pathname'
2
2
 
3
3
  class ExceptionNotifier < ActionMailer::Base
4
4
 
5
- @@config = {
5
+ #andrewroth reported that @@config gets clobbered because rails loads this class twice when installed as a plugin, and adding the ||= fixed it.
6
+ @@config ||= {
6
7
  # If left empty web hooks will not be engaged
7
8
  :web_hooks => [],
8
9
  :app_name => "[MYAPP]",
@@ -14,15 +15,13 @@ class ExceptionNotifier < ActionMailer::Base
14
15
  :subject_append => nil,
15
16
  # Include which sections of the exception email?
16
17
  :sections => %w(request session environment backtrace),
17
- # Only use this gem to render, never email
18
- :render_only => false,
19
18
  :skip_local_notification => true,
20
19
  :view_path => nil,
21
20
  #Error Notification will be sent if the HTTP response code for the error matches one of the following error codes
22
- :send_email_error_codes => %W( 405 500 503 ),
21
+ :notify_error_codes => %W( 405 500 503 ),
23
22
  #Error Notification will be sent if the error class matches one of the following error error classes
24
- :send_email_error_classes => %W( ),
25
- :send_email_other_errors => true,
23
+ :notify_error_classes => %W( ),
24
+ :notify_other_errors => true,
26
25
  :git_repo_path => nil,
27
26
  :template_root => "#{File.dirname(__FILE__)}/../views"
28
27
  }
@@ -6,13 +6,15 @@ require File.join(File.dirname(__FILE__), '..', 'lib', "super_exception_notifier
6
6
  # Add this path to ruby load path
7
7
  $:.unshift "#{File.dirname(__FILE__)}/../lib"
8
8
 
9
- require "hooks_notifier"
10
- require "exception_notifier"
11
- require "exception_notifiable"
12
- require "exception_notifier_helper"
13
- require "notifiable"
9
+ require "hooks_notifier" unless defined?(HooksNotifier)
10
+ require "exception_notifier" unless defined?(ExceptionNotifier)
11
+ require "exception_notifiable" unless defined?(ExceptionNotifiable)
12
+ require "exception_notifier_helper" unless defined?(ExceptionNotifierHelper)
13
+ require "notifiable" unless defined?(Notifiable)
14
14
 
15
- Object.class_eval do include Notifiable end
15
+ Object.class_eval do
16
+ include Notifiable
17
+ end
16
18
 
17
19
  #It appears that the view path is auto-added by rails... hmmm.
18
20
  #if ActionController::Base.respond_to?(:append_view_path)
@@ -3,5 +3,5 @@
3
3
  * data: <%= PP.pp(@request.session.instance_variable_get(:@data),"").gsub(/\n/, "\n ").strip %>
4
4
  <%else -%>
5
5
  * session id: <%= @request.session_options[:id] %>
6
- * data: <%= PP.pp(@request.session.data, "").gsub(/\n/, "\n ").strip %>
6
+ * data: <%= PP.pp(@request.session.to_hash, "").gsub(/\n/, "\n ").strip %>
7
7
  <% end -%>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pboling-super_exception_notifier
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.7
4
+ version: 1.6.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Boling
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2009-08-14 00:00:00 -07:00
14
+ date: 2009-08-15 00:00:00 -07:00
15
15
  default_executable:
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
@@ -24,7 +24,7 @@ dependencies:
24
24
  - !ruby/object:Gem::Version
25
25
  version: "2.1"
26
26
  version:
27
- description: "Allows customization of: * the sender address of the email * the recipient addresses * the text used to prefix the subject line * the HTTP status codes to send emails for * the error classes to send emails for * alternatively, the error classes to not send emails for * whether to send error emails or just render without sending anything * the HTTP status and status code that gets rendered with specific errors * the view path to the error page templates * custom errors, with custom error templates * define error layouts at application or controller level, or use the controller's own default layout, or no layout at all * get error notification for errors that occur in the console, using notifiable method * Override the gem's handling and rendering with explicit rescue statements inline."
27
+ description: "Allows customization of: * the sender address of the email * the recipient addresses * the text used to prefix the subject line * the HTTP status codes to send emails for * the error classes to send emails for * alternatively, the error classes to not send emails for * whether to send error emails or just render without sending anything * the HTTP status and status code that gets rendered with specific errors * the view path to the error page templates * custom errors, with custom error templates * define error layouts at application or controller level, or use the controller's own default layout, or no layout at all * get error notification for errors that occur in the console, using notifiable method * Override the gem's handling and rendering with explicit rescue statements inline. * Hooks into `git blame` output so you can get an idea of who (may) have introduced the bug * Hooks into other website services (e.g. you can send exceptions to to Switchub.com) * Specify which level of notification you would like with an array of optional styles of notification"
28
28
  email: peter.boling@gmail.com
29
29
  executables: []
30
30