wrangler 0.1.12 → 0.1.13
Sign up to get free protection for your applications and to get access to all the features.
data/{README → README.rdoc}
RENAMED
@@ -1,116 +1,82 @@
|
|
1
1
|
= Wrangler
|
2
2
|
|
3
3
|
== NOTE/DISCLAIMER
|
4
|
-
This gem is almost completely inspired by/ripped off the exception_notification
|
5
|
-
plugin/gem, but had to hack too much to get things to work with delayed_job
|
6
|
-
that I just decided to start from scratch. You'll see that much has been
|
7
|
-
borrowed however, so I owe a huge debt to the originals (exception_notification
|
8
|
-
[http://github.com/rails/exception_notification] and
|
9
|
-
super_exception_notification [http://github.com/pboling/exception_notification])
|
10
|
-
to help me recreate the Rails hacking.
|
4
|
+
This gem is almost completely inspired by/ripped off the exception_notification plugin/gem, but had to hack too much to get things to work with delayed_job that I just decided to start from scratch. You'll see that much has been borrowed however, so I owe a huge debt to the originals (exception_notification [http://github.com/rails/exception_notification] and super_exception_notification [http://github.com/pboling/exception_notification]) to help me recreate the Rails hacking.
|
11
5
|
|
12
|
-
If you don't really care about using delayed_job for your emailing, consider
|
13
|
-
going back to the originals, as they're likely better maintained.... ;)
|
6
|
+
If you don't really care about using delayed_job for your emailing, consider going back to the originals, as they're likely better maintained.... ;)
|
14
7
|
|
15
8
|
== Overview:
|
16
9
|
A gem for handling exceptions in a Rails application/environment.
|
17
10
|
|
18
11
|
Some highlights:
|
19
|
-
* Allows for rendering error pages and sending email notifications in case of
|
20
|
-
errors.
|
12
|
+
* Allows for rendering error pages and sending email notifications in case of errors.
|
21
13
|
* Allows for lots of configuring of which pages to show, whether to email or not.
|
22
|
-
* Allows for asynchronous emailing through delayed_job if available, but works
|
23
|
-
|
24
|
-
*
|
25
|
-
|
26
|
-
emailing application state at the time of the exception
|
27
|
-
* Allows email notification on exceptions thrown totally outside Controller
|
28
|
-
context, e.g. in a script run (with rails environment) in a cronjob or
|
29
|
-
delayed_job
|
30
|
-
* See TODO for things that are explicitly not included yet, but that could/
|
31
|
-
should be added
|
14
|
+
* Allows for asynchronous emailing through delayed_job if available, but works fine even if delayed_job not installed (email will be synchronous however)
|
15
|
+
* Will honor filter_parameters set in the controller including the Wrangler module (except if the parameters are in the URL for GETs) when logging and emailing application state at the time of the exception
|
16
|
+
* Allows email notification on exceptions thrown totally outside Controller context, e.g. in a script run (with rails environment) in a cronjob or delayed_job
|
17
|
+
* See TODO for things that are explicitly not included yet, but that could/should be added
|
32
18
|
|
33
19
|
== Quickstart
|
34
20
|
=== Bare Minimum
|
35
|
-
There are a lot of defaults set, so getting started should be pretty easy. In
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
class ApplicationController < ActionController::Base
|
40
|
-
include Wrangler
|
21
|
+
There are a lot of defaults set, so getting started should be pretty easy. In fact, if you don't want any email notifications, you basically just need to include the Wrangler module in your controller:
|
22
|
+
# application_controller.rb
|
23
|
+
class ApplicationController < ActionController::Base
|
24
|
+
include Wrangler
|
41
25
|
|
42
|
-
|
43
|
-
|
26
|
+
...
|
27
|
+
|
28
|
+
end
|
44
29
|
|
45
30
|
=== Enabling email notifications
|
46
|
-
Email notifications are configured to be sent with the default configuration,
|
47
|
-
but you'll need to specify from and to addresses for emails to actually be sent.
|
48
|
-
So that brings us to the configuration of Wrangler. Recommended: just create a
|
49
|
-
new initializer file (create a wrangler.rb (or whatever you want to name the file)
|
50
|
-
in RAILS_ROOT/config/initializers/wrangler.rb). In it, add the following:
|
31
|
+
Email notifications are configured to be sent with the default configuration, but you'll need to specify from and to addresses for emails to actually be sent. So that brings us to the configuration of Wrangler. Recommended: just create a new initializer file (create a wrangler.rb (or whatever you want to name the file) in RAILS_ROOT/config/initializers/wrangler.rb). In it, add the following:
|
51
32
|
|
52
33
|
Wrangler::ExceptionNotifier.configure do |notifier_config|
|
53
34
|
notifier_config.merge! :from_address => 'notifer@example.com',
|
54
35
|
:recipient_addresses => ['ops-team@example.com']
|
55
36
|
end
|
56
37
|
|
57
|
-
And, if you haven't already configured ActionMailer to send emails, you'll need
|
58
|
-
to do that (e.g. setting ActionMailer::Base.smtp_settings), and even after you
|
59
|
-
have, you may want to change some settings in order to send from a different
|
60
|
-
account from the one you may use to email your users (e.g. change the :user_name
|
61
|
-
for smtp_settings):
|
38
|
+
And, if you haven't already configured ActionMailer to send emails, you'll need to do that (e.g. setting ActionMailer::Base.smtp_settings), and even after you have, you may want to change some settings in order to send from a different account from the one you may use to email your users (e.g. change the :user_name for smtp_settings):
|
62
39
|
|
63
40
|
Wrangler::ExceptionNotifier.smtp_settings.merge! :user_name => 'notifier@mydomain.com'
|
64
41
|
|
65
42
|
(Recommend just putting that in the same wrangler.rb initializer you created above)
|
66
43
|
|
67
|
-
For more info on smtp_settings, see ActionMailer
|
44
|
+
For more info on smtp_settings, see ActionMailer [http://am.rubyonrails.org/]
|
68
45
|
|
69
46
|
== Configuration
|
70
|
-
There are two different classes that receive configuration, ExceptionHandler and
|
71
|
-
ExceptionNotifier.
|
47
|
+
There are two different classes that receive configuration, ExceptionHandler and ExceptionNotifier.
|
72
48
|
|
73
|
-
ExceptionHandler stores configurations about what to do about exceptions (whether to
|
74
|
-
handle them, email them, which error templates to render for each exception...).
|
49
|
+
ExceptionHandler stores configurations about what to do about exceptions (whether to handle them, email them, which error templates to render for each exception...).
|
75
50
|
|
76
|
-
ExceptionNotifier handles the sending of emails when exceptions occur, so
|
77
|
-
stores configurations about where to send the emails.
|
51
|
+
ExceptionNotifier handles the sending of emails when exceptions occur, so stores configurations about where to send the emails.
|
78
52
|
|
79
|
-
You override defaults on each using the same syntax (as seen above) by calling the
|
80
|
-
configure() method on the class and using the config hash that is yielded to
|
81
|
-
set your configurations. See the method documentation for the configure() methods
|
82
|
-
themselves, but here's the basic idea:
|
53
|
+
You override defaults on each using the same syntax (as seen above) by calling the configure() method on the class and using the config hash that is yielded to set your configurations. See the method documentation for the configure() methods themselves, but here's the basic idea:
|
83
54
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
55
|
+
Wrangler::ExceptionHandler.configure do |handler_config|
|
56
|
+
handler_config[:key1] = value1
|
57
|
+
handler_config[:key2] = value2
|
58
|
+
handler_config[:key_for_a_hash].merge! :subkey => value
|
59
|
+
handler_config[:key_for_an_array] << another_value
|
60
|
+
end
|
90
61
|
|
91
|
-
|
62
|
+
OR
|
92
63
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
64
|
+
Wrangler::ExceptionHandler.configure do |handler_config|
|
65
|
+
handler_config.merge! :key1 => value1,
|
66
|
+
:key2 => value2,
|
67
|
+
handler_config[:key_for_a_hash].merge! :subkey => value
|
68
|
+
handler_config[:key_for_an_array] << another_value
|
69
|
+
end
|
99
70
|
|
100
71
|
(same with Wrangler::ExceptionNotifier, except different classname)
|
101
72
|
|
102
|
-
Most configurations are single values (e.g. nums or strings),
|
103
|
-
but some are hashes or arrays. You can either overwrite the hashes/arrays, or
|
104
|
-
selectively delete, or just append. Recommend just appending to the defaults
|
105
|
-
in most cases, but if you know what you're doing, you can do whatever you like!
|
73
|
+
Most configurations are single values (e.g. nums or strings), but some are hashes or arrays. You can either overwrite the hashes/arrays, or selectively delete, or just append. Recommend just appending to the defaults in most cases, but if you know what you're doing, you can do whatever you like!
|
106
74
|
|
107
|
-
Here is the full set of configuration values for both classes, as well as their
|
108
|
-
default values (pasted in from the classes, so you can check the code directly
|
109
|
-
to make sure you've got the latest! :) ):
|
75
|
+
Here is the full set of configuration values for both classes, as well as their default values (pasted in from the classes, so you can check the code directly to make sure you've got the latest! :) ):
|
110
76
|
|
111
|
-
|
112
|
-
|
113
|
-
|
77
|
+
####################
|
78
|
+
# ExceptionHandler:
|
79
|
+
####################
|
114
80
|
|
115
81
|
:app_name => '',
|
116
82
|
:handle_local_errors => false,
|
@@ -161,9 +127,9 @@ to make sure you've got the latest! :) ):
|
|
161
127
|
:absolute_last_resort_default_error_template =>
|
162
128
|
File.join(WRANGLER_ROOT,'rails','app','views','wrangler','500.html')
|
163
129
|
|
164
|
-
|
165
|
-
|
166
|
-
|
130
|
+
#####################
|
131
|
+
# ExceptionNotifier:
|
132
|
+
#####################
|
167
133
|
|
168
134
|
# who the emails will be coming from. if nil or missing or empty string,
|
169
135
|
# effectively disables email notification
|
@@ -181,43 +147,27 @@ to make sure you've got the latest! :) ):
|
|
181
147
|
:mailer_template_root => File.join(WRANGLER_ROOT, 'views')
|
182
148
|
|
183
149
|
== Search algorithm for error templates (given an exception and a status_code):
|
184
|
-
When trying to find an appropriate error page template to render, Wrangler
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
** config[:error_template_dir]/
|
203
|
-
** RAILS_ROOT/public/
|
204
|
-
** WRANGLER_ROOT/rails/app/views/wrangler/
|
205
|
-
# if there is a file/template corresponding to a parent class name of the
|
206
|
-
exception (underscorified) one of the following locations, use that:
|
207
|
-
** config[:error_template_dir]/
|
208
|
-
** RAILS_ROOT/public/
|
209
|
-
** WRANGLER_ROOT/rails/app/views/wrangler/
|
210
|
-
# :default_error_template
|
211
|
-
# :absolute_last_resort_default_error_template
|
150
|
+
When trying to find an appropriate error page template to render, Wrangler goes through several different attempts to locate an appropriate template, beginning with templates you've explicitly associated with the exception class or status code that has arisen...and on through to assuming default file naming conventions and finally failsafe default templates.
|
151
|
+
|
152
|
+
1. if there is an explicit mapping from the exception to an error page in :error_class_xxx_templates, use that
|
153
|
+
1. if there is a mapping in :error_class_templates for which the exception returns true to an is_a? call, use that
|
154
|
+
1. if there is a file/template corresponding to the exception name (underscorified) in one of the following locations, use that:
|
155
|
+
config[:error_template_dir]/
|
156
|
+
RAILS_ROOT/public/
|
157
|
+
WRANGLER_ROOT/rails/app/views/wrangler/
|
158
|
+
1. if there is a file/template corresponding to the status code (e.g. named ###.html.erb where ### is the status code) in one of the following locations, use that:
|
159
|
+
config[:error_template_dir]/
|
160
|
+
RAILS_ROOT/public/
|
161
|
+
WRANGLER_ROOT/rails/app/views/wrangler/
|
162
|
+
1. if there is a file/template corresponding to a parent class name of the exception (underscorified) one of the following locations, use that:
|
163
|
+
config[:error_template_dir]/
|
164
|
+
RAILS_ROOT/public/
|
165
|
+
WRANGLER_ROOT/rails/app/views/wrangler/
|
166
|
+
1. :default_error_template
|
167
|
+
1. :absolute_last_resort_default_error_template
|
212
168
|
|
213
169
|
== Using outside a Controller:
|
214
|
-
You can still use Wrangler outside the context of a Controller class. If you'll
|
215
|
-
be running within the context of an object instance, you can just include Wrangler
|
216
|
-
in the object's class. If you'll be running 'static' code, you can refer to
|
217
|
-
relevant methods via the Wrangler module. Note that in both cases, you'll be
|
218
|
-
calling the notify_on_error() method. Also note that the notify_on_error()
|
219
|
-
method will re-raise the exception that occurred in the block, so you may want
|
220
|
-
to begin/rescue/end around the notify_on_error() method call
|
170
|
+
You can still use Wrangler outside the context of a Controller class. If you'll be running within the context of an object instance, you can just include Wrangler in the object's class. If you'll be running 'static' code, you can refer to relevant methods via the Wrangler module. Note that in both cases, you'll be calling the notify_on_error() method. Also note that the notify_on_error() method will re-raise the exception that occurred in the block, so you may want to begin/rescue/end around the notify_on_error() method call
|
221
171
|
|
222
172
|
using in an object instance:
|
223
173
|
|
@@ -238,9 +188,7 @@ using 'statically':
|
|
238
188
|
Wrangler::notify_on_error { run_some_method_that_might_raise_exceptions }
|
239
189
|
|
240
190
|
== Maintaining the Wrangler gem
|
241
|
-
Should be pretty straightforward. Note that we're using jeweler, so the .gemspec
|
242
|
-
isn't included in the git repos; it gets generated dynamically from the settings
|
243
|
-
in Rakefile.
|
191
|
+
Should be pretty straightforward. Note that we're using jeweler, so the .gemspec isn't included in the git repos; it gets generated dynamically from the settings in Rakefile.
|
244
192
|
|
245
193
|
To build:
|
246
194
|
|
@@ -249,8 +197,7 @@ To build:
|
|
249
197
|
rake build
|
250
198
|
|
251
199
|
To test:
|
252
|
-
Now at least, wrangler testing is all manual, which is bad (see TODO). So to
|
253
|
-
test, try at least some of the following cases:
|
200
|
+
Now at least, wrangler testing is all manual, which is bad (see TODO). So to test, try at least some of the following cases:
|
254
201
|
* enable/disable local exception handling
|
255
202
|
* enable/disable local notification
|
256
203
|
* enable/disable delayed_job notification
|
@@ -126,7 +126,7 @@ module Wrangler
|
|
126
126
|
# handler_config[:key_for_a_hash].merge! :subkey => value
|
127
127
|
# handler_config[:key_for_an_array] << another_value
|
128
128
|
# end
|
129
|
-
#
|
129
|
+
#
|
130
130
|
# NOTE: sure, you can change this configuration on the fly in your app, but
|
131
131
|
# we don't recommend it. plus, if you do and you're using delayed_job, there
|
132
132
|
# may end up being configuration differences between the rails process and
|
@@ -200,16 +200,27 @@ module Wrangler
|
|
200
200
|
render_errors = options[:render_errors] || false
|
201
201
|
proc_name = options[:proc_name] || config[:app_name]
|
202
202
|
|
203
|
-
status_code =
|
203
|
+
status_code =
|
204
|
+
Wrangler::ExceptionHandler.status_code_for_exception(exception)
|
204
205
|
request_data = request_data_from_request(request) unless request.nil?
|
205
206
|
|
206
207
|
log_exception(exception, request_data, status_code)
|
207
208
|
|
208
|
-
|
209
|
-
|
209
|
+
if exception.is_a?(Class)
|
210
|
+
exception_classname = exception.name
|
211
|
+
else
|
212
|
+
exception_classname = exception.class.name
|
213
|
+
end
|
214
|
+
|
215
|
+
if exception.respond_to?(:message)
|
216
|
+
exception_string = exception.message
|
217
|
+
else
|
218
|
+
exception_string = exception.to_s
|
219
|
+
end
|
210
220
|
|
211
221
|
if notify_on_exception?(exception, status_code)
|
212
222
|
if notify_with_delayed_job?
|
223
|
+
|
213
224
|
# don't pass in request as it contains not-easily-serializable stuff
|
214
225
|
log_error "Wrangler sending email notification asynchronously"
|
215
226
|
Wrangler::ExceptionNotifier.send_later(:deliver_exception_notification,
|
@@ -62,7 +62,12 @@ module Wrangler
|
|
62
62
|
def log_exception(exception, request_data = nil, status_code = nil)
|
63
63
|
msgs = []
|
64
64
|
msgs << "An exception was caught (#{exception.class.name}):"
|
65
|
-
|
65
|
+
|
66
|
+
if exception.respond_to?(:message)
|
67
|
+
msgs << exception.message
|
68
|
+
else
|
69
|
+
msgs << exception.to_s
|
70
|
+
end
|
66
71
|
|
67
72
|
unless request_data.blank?
|
68
73
|
msgs << "Request params were:"
|
data/lib/wrangler.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
<%
|
2
2
|
# NOTE: be very careful pulling data out of request in the view...it is
|
3
|
-
# NOT cleaned, and may contain private data (e.g. passwords), so
|
3
|
+
# NOT cleaned, and may contain private data (e.g. passwords), so
|
4
4
|
# scrutinize any use of @request in the views!
|
5
5
|
#-----------------------------------------------------------------------------
|
6
6
|
-%>
|
@@ -10,7 +10,10 @@
|
|
10
10
|
|
11
11
|
A <%= @exception_classname %> occurred:
|
12
12
|
* <%= @exception_message %>
|
13
|
+
<% unless @backtrace.blank? -%>
|
13
14
|
in <%= @backtrace.first %>
|
15
|
+
<% end -%>
|
16
|
+
|
14
17
|
|
15
18
|
<% unless @backtrace.blank? -%>
|
16
19
|
--------------------------------------------------
|
data/wrangler.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{wrangler}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.13"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Brian Percival"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-02-18}
|
13
13
|
s.description = %q{A gem for handling exceptions thrown inside your Rails app. If you include the
|
14
14
|
gem in your application controller, wrangler will render the error pages you
|
15
15
|
configure for each exception or HTTP error code. It will also handle notifying
|
@@ -24,11 +24,12 @@ get started and what configuration options are available.
|
|
24
24
|
s.email = %q{percivalatumamibuddotcom}
|
25
25
|
s.extra_rdoc_files = [
|
26
26
|
"LICENSE",
|
27
|
-
"README",
|
27
|
+
"README.rdoc",
|
28
28
|
"TODO"
|
29
29
|
]
|
30
30
|
s.files = [
|
31
|
-
"
|
31
|
+
"README.rdoc",
|
32
|
+
"lib/wrangler.rb",
|
32
33
|
"lib/wrangler/exception_handler.rb",
|
33
34
|
"lib/wrangler/exception_notifier.rb",
|
34
35
|
"lib/wrangler/wrangler_exceptions.rb",
|
@@ -51,7 +52,7 @@ get started and what configuration options are available.
|
|
51
52
|
s.rdoc_options = ["--charset=UTF-8"]
|
52
53
|
s.require_paths = ["lib"]
|
53
54
|
s.rubygems_version = %q{1.3.5}
|
54
|
-
s.summary = %q{Handles exceptions in rails apps, rendering error pages and emailing when exceptions occur}
|
55
|
+
s.summary = %q{Handles exceptions in rails apps, rendering error pages and emailing when exceptions occur. Spun off from some work at discovereads.com}
|
55
56
|
|
56
57
|
if s.respond_to? :specification_version then
|
57
58
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wrangler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Percival
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-
|
12
|
+
date: 2010-02-18 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -41,9 +41,10 @@ extensions: []
|
|
41
41
|
|
42
42
|
extra_rdoc_files:
|
43
43
|
- LICENSE
|
44
|
-
- README
|
44
|
+
- README.rdoc
|
45
45
|
- TODO
|
46
46
|
files:
|
47
|
+
- README.rdoc
|
47
48
|
- lib/wrangler.rb
|
48
49
|
- lib/wrangler/exception_handler.rb
|
49
50
|
- lib/wrangler/exception_notifier.rb
|
@@ -63,7 +64,6 @@ files:
|
|
63
64
|
- views/wrangler/exception_notifier/exception_notification.text.plain.erb
|
64
65
|
- wrangler.gemspec
|
65
66
|
- LICENSE
|
66
|
-
- README
|
67
67
|
- TODO
|
68
68
|
has_rdoc: true
|
69
69
|
homepage: http://github.com/bmpercy/wrangler
|
@@ -92,6 +92,6 @@ rubyforge_project:
|
|
92
92
|
rubygems_version: 1.3.5
|
93
93
|
signing_key:
|
94
94
|
specification_version: 3
|
95
|
-
summary: Handles exceptions in rails apps, rendering error pages and emailing when exceptions occur
|
95
|
+
summary: Handles exceptions in rails apps, rendering error pages and emailing when exceptions occur. Spun off from some work at discovereads.com
|
96
96
|
test_files: []
|
97
97
|
|