wrangler 0.1.14 → 0.1.15

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,8 +1,8 @@
1
1
  module Wrangler
2
2
 
3
- # a utility method that should only be used internally. don't call this; it
4
- # should only be called once by the Config class and you can get/set it there.
5
- # returns a mapping from exception classes to http status codes
3
+ # A utility method that should only be used internal to wrangler. don't call
4
+ # this; it should only be called once by the Config class and you can get/set
5
+ # it there. returns a mapping from exception classes to http status codes
6
6
  #-----------------------------------------------------------------------------
7
7
  def self.codes_for_exception_classes
8
8
  classes = {
@@ -36,11 +36,11 @@ module Wrangler
36
36
 
37
37
  # class that holds configuration for the exception handling logic. may also
38
38
  # include a helper method or two, but the main interaction with
39
- # ExceptionHandler is setting and getting config, e.g.
39
+ # +ExceptionHandler+ is setting and getting config, e.g.
40
40
  #
41
- # Wrangler::ExceptionHandler.configure do |handler_config|
42
- # handler_config.merge! :key => value
43
- # end
41
+ # Wrangler::ExceptionHandler.configure do |handler_config|
42
+ # handler_config.merge! :key => value
43
+ # end
44
44
  #-----------------------------------------------------------------------------
45
45
  class ExceptionHandler
46
46
 
@@ -100,7 +100,7 @@ module Wrangler
100
100
 
101
101
  cattr_accessor :config
102
102
 
103
- # allows for overriding default configuration settings.
103
+ # Allows for overriding default configuration settings.
104
104
  # in your environment.rb or environments/<env name>.rb, use a block that
105
105
  # accepts one argument
106
106
  # * recommend against naming it 'config' as you will probably be calling it
@@ -111,23 +111,23 @@ module Wrangler
111
111
  # overwriting the arrays/hashes completely unless you don't want to
112
112
  # take advantage of lots of out-of-the-box config
113
113
  #
114
- # Wrangler::ExceptionHandler.configure do |handler_config|
115
- # handler_config[:key1] = value1
116
- # handler_config[:key2] = value2
117
- # handler_config[:key_for_a_hash].merge! :subkey => value
118
- # handler_config[:key_for_an_array] << another_value
119
- # end
114
+ # Wrangler::ExceptionHandler.configure do |handler_config|
115
+ # handler_config[:key1] = value1
116
+ # handler_config[:key2] = value2
117
+ # handler_config[:key_for_a_hash].merge! :subkey => value
118
+ # handler_config[:key_for_an_array] << another_value
119
+ # end
120
120
  #
121
121
  # OR
122
122
  #
123
- # Wrangler::ExceptionHandler.configure do |handler_config|
124
- # handler_config.merge! :key1 => value1,
125
- # :key2 => value2,
126
- # handler_config[:key_for_a_hash].merge! :subkey => value
127
- # handler_config[:key_for_an_array] << another_value
128
- # end
123
+ # Wrangler::ExceptionHandler.configure do |handler_config|
124
+ # handler_config.merge! :key1 => value1,
125
+ # :key2 => value2,
126
+ # handler_config[:key_for_a_hash].merge! :subkey => value
127
+ # handler_config[:key_for_an_array] << another_value
128
+ # end
129
129
  #
130
- # NOTE: sure, you can change this configuration on the fly in your app, but
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
133
133
  # the delayed_job process, resulting in unexpected behavior. so recommend
@@ -164,17 +164,27 @@ module Wrangler
164
164
  # execute the code block passed as an argument, and follow notification
165
165
  # rules if an exception bubbles out of the block.
166
166
  #
167
- # return value:
168
- # * if an exception bubbles out of the block, the exception is re-raised to
169
- # calling code.
170
- # * otherwise, returns nil
167
+ # == arguments
168
+ # [proc_name] a name for the chunk of code you're running, included in logs
169
+ # and in the email notifications' subject line. optional, default
170
+ # is nil (nothing will be displayed).
171
+ # [message] a message to include in any logs regarding exceptions thrown.
172
+ # useful to explain what the context of the code was to help
173
+ # diagnose. optional, default is nil (no message will be displayed
174
+ # other than the exception's own message).
175
+ #
176
+ # == return value
177
+ # * if an exception bubbles out of the block, the exception is re-raised to
178
+ # calling code.
179
+ # * otherwise, returns nil
171
180
  #-----------------------------------------------------------------------------
172
- def notify_on_error(proc_name = nil, &block)
181
+ def notify_on_error(proc_name = nil, message = nil, &block)
173
182
  begin
174
183
  yield
175
184
  rescue => exception
176
185
  options = {}
177
186
  options.merge! :proc_name => proc_name unless proc_name.nil?
187
+ options.merge! :error_messages => message unless message.nil?
178
188
  handle_exception(exception, options)
179
189
  end
180
190
 
@@ -192,13 +202,14 @@ module Wrangler
192
202
  # the error condition will get logged and may result in notification,
193
203
  # according to configuration see notify_on_exception?
194
204
  #
195
- # arguments:
196
- # - error_messages: a message or array of messages (each gets logged on
197
- # separate log call) capturing the error condition that
198
- # occurred. this will get logged AND sent in any
199
- # notifications sent
205
+ # == arguments
206
+ # [error_messages] a message or array of messages (each gets logged on
207
+ # separate log call) capturing the error condition that
208
+ # occurred. this will get logged AND sent in any
209
+ # notifications sent
200
210
  #
201
- # options: also, any of the options accepted by handle_exception
211
+ # == options
212
+ # also, any of the options accepted by handle_exception
202
213
  #-----------------------------------------------------------------------------
203
214
  def handle_error(error_messages, options = {})
204
215
  options.merge! :error_messages => error_messages
@@ -209,21 +220,21 @@ module Wrangler
209
220
  # the main exception-handling method. decides whether to notify or not,
210
221
  # whether to render an error page or not, and to make it happen.
211
222
  #
212
- # arguments:
213
- # - exception: the exception that was caught. can be nil, but should
214
- # only be nil if notifications should always be sent,
215
- # as notification rules are bypassed this case
223
+ # == arguments
224
+ # [exception] the exception that was caught. can be nil, but should
225
+ # only be nil if notifications should always be sent,
226
+ # as notification rules are bypassed this case
216
227
  #
217
- # options:
218
- # :error_messages: any additional message to log and send in notification.
219
- # can also be an array of messages (each gets logged
220
- # separately)
221
- # :request: the request object (if any) that resulted in the exception
222
- # :render_errors: boolean indicating if an error page should be rendered
223
- # or not (Rails only)
224
- # :proc_name: a string representation of the process/app that was running
225
- # when the exception was raised. default value is
226
- # Wrangler::ExceptionHandler.config[:app_name].
228
+ # == options
229
+ # [error_messages] any additional message to log and send in notification.
230
+ # can also be an array of messages (each gets logged
231
+ # separately)
232
+ # [request] the request object (if any) that resulted in the exception
233
+ # [render_errors] boolean indicating if an error page should be rendered
234
+ # or not (Rails only). default => false
235
+ # [proc_name] a string representation of the process/app that was running
236
+ # when the exception was raised. default value is
237
+ # Wrangler::ExceptionHandler.config[:app_name].
227
238
  #-----------------------------------------------------------------------------
228
239
  def handle_exception(exception, options = {})
229
240
  request = options[:request]
@@ -237,18 +248,22 @@ module Wrangler
237
248
  backtrace = caller
238
249
  end
239
250
 
251
+ # extract the relevant request data and also filter out any params
252
+ # that should NOT be logged/emailed (passwords etc.)
253
+ request_data = request_data_from_request(request) unless request.nil?
254
+
240
255
  if exception.nil?
241
256
  exception_classname = nil
242
257
  status_code = nil
243
258
  log_error error_messages
244
259
  log_error backtrace
260
+ log_error "Request params were:"
261
+ log_error request_data.to_yaml
245
262
  error_string = ''
246
263
  else
247
264
  status_code =
248
265
  Wrangler::ExceptionHandler.status_code_for_exception(exception)
249
266
 
250
- request_data = request_data_from_request(request) unless request.nil?
251
-
252
267
  log_exception(exception, request_data, status_code, error_messages)
253
268
 
254
269
  if exception.is_a?(Class)
@@ -297,10 +312,10 @@ module Wrangler
297
312
  end
298
313
 
299
314
 
300
- # determine if the current context (local?, background) indicates that a
315
+ # determine if the current context (+local?+, +background+) indicates that a
301
316
  # notification should be sent. this applies all of the rules around
302
317
  # notifications EXCEPT for what the current exception or status code is
303
- # (see notify_on_exception? for that)
318
+ # (see +notify_on_exception?+ for that)
304
319
  #-----------------------------------------------------------------------------
305
320
  def notify_in_context?
306
321
  if self.respond_to?(:local_request?)
data/lib/wrangler.rb CHANGED
@@ -87,6 +87,11 @@ module Wrangler
87
87
 
88
88
 
89
89
  # extract a hash of relevant (and serializable) parameters from a request
90
+ # NOTE: will obey +filter_paramters+ on any class including the module,
91
+ # avoid logging any data in the request that the app wouldn't log itself.
92
+ # +filter_paramters+ must follow the rails convention of returning
93
+ # the association but with the value obscured in some way
94
+ # (e.g. "[FILTERED]"). see +filter_paramter_logging+ .
90
95
  #---------------------------------------------------------------------------
91
96
  def request_data_from_request(request)
92
97
  return nil if request.nil?
@@ -8,7 +8,7 @@
8
8
  <%= @protocol %><%= @host %><%= @uri %>
9
9
  <% end -%>
10
10
 
11
- A<%= @exception_classname || "n error" %> occurred:
11
+ A<%= "/an #{@exception_classname}" || "n error" %> occurred:
12
12
  <%= @error_message %>
13
13
  <% if @additional_messages.is_a?(Array) -%>
14
14
  <%= @additional_messages.join("\n ") %>
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.14"
8
+ s.version = "0.1.15"
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-02-19}
12
+ s.date = %q{2010-03-29}
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
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.14
4
+ version: 0.1.15
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-02-19 00:00:00 -08:00
12
+ date: 2010-03-29 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency