exception_handling 2.3.0 → 2.4.0.pre.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6d1c207f35c692b5d0bcd7bb605747c30222c7db
4
- data.tar.gz: 34d368d277e241f4ae61cae3ecdd010aeb9e0832
3
+ metadata.gz: becd17dbab6068dab7abb6b81bd5af8d4d48b63b
4
+ data.tar.gz: 7be8edf728c439e0fbe3703a582c66523f6606ac
5
5
  SHA512:
6
- metadata.gz: f897c084f3df5d5cb2b8ca91501d2a0af1956f3080f2f77e5b11216291cc5fbbe22f3081e6e35b49609a29c9e87e3ad1eef813c7c566c1bc3940e4ed9363bfd7
7
- data.tar.gz: 1f3fa7be3cab1bb4022fe1900220333dd9133ceca05083c84bac5b5f34ff72d9621d3ce711fdbbdcd5611b6876d431067d78e6ae937a7c9dcf3c4f65d99f4202
6
+ metadata.gz: 520560299d17e85a2bf1e52e95d633401efc963e6cb505f1d644f8ee4826d49c72a808613e343fe86f6e09ad2b23cd092f040f9a116a9f19f7c123e35635e9ca
7
+ data.tar.gz: db6689caa551e772dd6686020e5885f2e9eefdc45d24b773b67a04619c3f8a9404fb77ae28345607260386dd298811b27c376c7b13351f09300341e14ba2c036
data/Gemfile.lock CHANGED
@@ -8,7 +8,7 @@ GIT
8
8
  PATH
9
9
  remote: .
10
10
  specs:
11
- exception_handling (2.3.0)
11
+ exception_handling (2.4.0.pre.1)
12
12
  actionmailer (~> 4.2)
13
13
  actionpack (~> 4.2)
14
14
  activesupport (~> 4.2)
@@ -15,6 +15,10 @@ Gem::Specification.new do |spec|
15
15
  spec.name = "exception_handling"
16
16
  spec.require_paths = ["lib"]
17
17
  spec.version = ExceptionHandling::VERSION
18
+ spec.metadata = {
19
+ "source_code_uri" => "https://github.com/Invoca/exception_handling",
20
+ "allowed_push_host" => "https://rubygems.org"
21
+ }
18
22
 
19
23
  spec.add_dependency 'actionmailer', '~> 4.2'
20
24
  spec.add_dependency 'actionpack', '~> 4.2'
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ExceptionHandling
4
- VERSION = '2.3.0'
4
+ VERSION = '2.4.0.pre.1'
5
5
  end
@@ -180,15 +180,15 @@ module ExceptionHandling # never included
180
180
  # Functional Test Operation:
181
181
  # Calls into handle_stub_log_error and returns. no log file. no honeybadger
182
182
  #
183
- def log_error(exception_or_string, exception_context = '', controller = nil, treat_like_warning: false, **log_context, &data_callback)
183
+ def log_error(exception_or_string, exception_context = '', treat_like_warning: false, **log_context, &data_callback)
184
184
  ex = make_exception(exception_or_string)
185
185
  timestamp = set_log_error_timestamp
186
- exception_info = ExceptionInfo.new(ex, exception_context, timestamp, controller || current_controller, data_callback)
186
+ exception_info = ExceptionInfo.new(ex, exception_context, timestamp, current_controller, data_callback)
187
187
 
188
188
  if stub_handler
189
189
  stub_handler.handle_stub_log_error(exception_info.data)
190
190
  else
191
- write_exception_to_log(ex, exception_context, timestamp, **log_context)
191
+ write_exception_to_log(ex, exception_context, timestamp, log_context)
192
192
  external_notification_results = unless treat_like_warning || ex.is_a?(Warning)
193
193
  send_external_notifications(exception_info)
194
194
  end || {}
@@ -208,9 +208,9 @@ module ExceptionHandling # never included
208
208
  #
209
209
  # Write an exception out to the log file using our own custom format.
210
210
  #
211
- def write_exception_to_log(ex, exception_context, timestamp, **log_context)
211
+ def write_exception_to_log(ex, exception_context, timestamp, log_context = {})
212
212
  ActiveSupport::Deprecation.silence do
213
- ExceptionHandling.logger.fatal("\nExceptionHandlingError (Error:#{timestamp}) #{ex.class} #{exception_context} (#{encode_utf8(ex.message.to_s)}):\n " + clean_backtrace(ex).join("\n ") + "\n\n", **log_context)
213
+ ExceptionHandling.logger.fatal("\nExceptionHandlingError (Error:#{timestamp}) #{ex.class} #{exception_context} (#{encode_utf8(ex.message.to_s)}):\n " + clean_backtrace(ex).join("\n ") + "\n\n", log_context)
214
214
  end
215
215
  end
216
216
 
@@ -275,33 +275,33 @@ module ExceptionHandling # never included
275
275
  end
276
276
  end
277
277
 
278
- def log_warning(message, **log_context)
278
+ def log_warning(message, log_context = {})
279
279
  warning = Warning.new(message)
280
280
  warning.set_backtrace([])
281
281
  log_error(warning, **log_context)
282
282
  end
283
283
 
284
- def log_info(message, **log_context)
285
- ExceptionHandling.logger.info(message, **log_context)
284
+ def log_info(message, log_context = {})
285
+ ExceptionHandling.logger.info(message, log_context)
286
286
  end
287
287
 
288
- def log_debug(message, **log_context)
289
- ExceptionHandling.logger.debug(message, **log_context)
288
+ def log_debug(message, log_context = {})
289
+ ExceptionHandling.logger.debug(message, log_context)
290
290
  end
291
291
 
292
- def ensure_safe(exception_context = "", **log_context)
292
+ def ensure_safe(exception_context = "", log_context = {})
293
293
  yield
294
294
  rescue => ex
295
- log_error ex, exception_context, **log_context
295
+ log_error(ex, exception_context, **log_context)
296
296
  nil
297
297
  end
298
298
 
299
- def ensure_completely_safe(exception_context = "", **log_context)
299
+ def ensure_completely_safe(exception_context = "", log_context = {})
300
300
  yield
301
301
  rescue SystemExit, SystemStackError, NoMemoryError, SecurityError, SignalException
302
302
  raise
303
303
  rescue Exception => ex
304
- log_error ex, exception_context, log_context
304
+ log_error(ex, exception_context, **log_context)
305
305
  nil
306
306
  end
307
307
 
@@ -311,26 +311,26 @@ module ExceptionHandling # never included
311
311
  escalate(email_subject, ex, last_exception_timestamp, production_support_recipients)
312
312
  end
313
313
 
314
- def escalate_error(exception_or_string, email_subject, custom_recipients = nil, **log_context)
314
+ def escalate_error(exception_or_string, email_subject, custom_recipients = nil, log_context = {})
315
315
  ex = make_exception(exception_or_string)
316
316
  log_error(ex, **log_context)
317
317
  escalate(email_subject, ex, last_exception_timestamp, custom_recipients)
318
318
  end
319
319
 
320
- def escalate_warning(message, email_subject, custom_recipients = nil, **log_context)
320
+ def escalate_warning(message, email_subject, custom_recipients = nil, log_context = {})
321
321
  ex = Warning.new(message)
322
322
  log_error(ex, **log_context)
323
323
  escalate(email_subject, ex, last_exception_timestamp, custom_recipients)
324
324
  end
325
325
 
326
- def ensure_escalation(email_subject, custom_recipients = nil, **log_context)
326
+ def ensure_escalation(email_subject, custom_recipients = nil, log_context = {})
327
327
  yield
328
328
  rescue => ex
329
- escalate_error(ex, email_subject, custom_recipients, **log_context)
329
+ escalate_error(ex, email_subject, custom_recipients, log_context)
330
330
  nil
331
331
  end
332
332
 
333
- def alert_warning(exception_or_string, alert_name, exception_context, **log_context)
333
+ def alert_warning(exception_or_string, alert_name, exception_context, log_context)
334
334
  ex = make_exception(exception_or_string)
335
335
  log_error(ex, exception_context, **log_context)
336
336
  begin
@@ -340,10 +340,10 @@ module ExceptionHandling # never included
340
340
  end
341
341
  end
342
342
 
343
- def ensure_alert(alert_name, exception_context, **log_context)
343
+ def ensure_alert(alert_name, exception_context, log_context = {})
344
344
  yield
345
345
  rescue => ex
346
- alert_warning(ex, alert_name, exception_context, **log_context)
346
+ alert_warning(ex, alert_name, exception_context, log_context)
347
347
  nil
348
348
  end
349
349
 
@@ -360,7 +360,7 @@ module ExceptionHandling # never included
360
360
  result
361
361
  end
362
362
 
363
- def log_periodically(exception_key, interval, message, **log_context)
363
+ def log_periodically(exception_key, interval, message, log_context = {})
364
364
  self.periodic_exception_intervals ||= {}
365
365
  last_logged = self.periodic_exception_intervals[exception_key]
366
366
  if !last_logged || ((last_logged + interval) < Time.now)
@@ -447,7 +447,7 @@ module ExceptionHandling # never included
447
447
  yield
448
448
  end
449
449
  rescue StandardError, MailerTimeout => ex
450
- log_error(ex, "ExceptionHandling::safe_email_deliver", nil, treat_like_warning: true)
450
+ log_error(ex, "ExceptionHandling::safe_email_deliver", treat_like_warning: true)
451
451
  end
452
452
 
453
453
  def make_exception(exception_or_string)
data/test/test_helper.rb CHANGED
@@ -27,15 +27,15 @@ class LoggerStub
27
27
  clear
28
28
  end
29
29
 
30
- def info(message, **log_context)
30
+ def info(message, log_context = {})
31
31
  logged << { message: message, context: log_context }
32
32
  end
33
33
 
34
- def warn(message, **log_context)
34
+ def warn(message, log_context = {})
35
35
  logged << { message: message, context: log_context }
36
36
  end
37
37
 
38
- def fatal(message, **log_context)
38
+ def fatal(message, log_context = {})
39
39
  logged << { message: message, context: log_context }
40
40
  end
41
41
 
@@ -110,7 +110,14 @@ class ExceptionHandlingTest < ActiveSupport::TestCase
110
110
  end
111
111
 
112
112
  context "#log_error" do
113
- should "take in additional keyword args as logging context and pass them to the logger" do
113
+ should "take in additional keyword args as logging context and pass them to the logger (using preferrred log_context:)" do
114
+ ExceptionHandling.log_error('This is an Error', 'This is the prefix context', service_name: 'exception_handling')
115
+ assert_match(/This is an Error/, logged_excluding_reload_filter.last[:message])
116
+ assert_not_empty logged_excluding_reload_filter.last[:context]
117
+ assert_equal({ service_name: 'exception_handling' }, logged_excluding_reload_filter.last[:context])
118
+ end
119
+
120
+ should "take in additional keyword args as logging context and pass them to the logger (using **)" do
114
121
  ExceptionHandling.log_error('This is an Error', 'This is the prefix context', service_name: 'exception_handling')
115
122
  assert_match(/This is an Error/, logged_excluding_reload_filter.last[:message])
116
123
  assert_not_empty logged_excluding_reload_filter.last[:context]
@@ -196,7 +203,7 @@ class ExceptionHandlingTest < ActiveSupport::TestCase
196
203
 
197
204
  should "include logging context in the exception data" do
198
205
  ExceptionHandling.post_log_error_hook = method(:log_error_callback_config)
199
- ExceptionHandling.log_error(StandardError.new("Some Exception"), "mooo", nil, treat_like_warning: true, log_context_test: "contextual_logging")
206
+ ExceptionHandling.log_error(StandardError.new("Some Exception"), "mooo", treat_like_warning: true, log_context_test: "contextual_logging")
200
207
 
201
208
  expected_log_context = {
202
209
  "log_context_test" => "contextual_logging"
@@ -543,6 +550,10 @@ class ExceptionHandlingTest < ActiveSupport::TestCase
543
550
  end
544
551
 
545
552
  context "with Honeybadger defined" do
553
+ teardown do
554
+ ExceptionHandling.current_controller = nil
555
+ end
556
+
546
557
  should "not send_exception_to_honeybadger when log_warning is executed" do
547
558
  dont_allow(ExceptionHandling).send_exception_to_honeybadger
548
559
  ExceptionHandling.log_warning("This should not go to honeybadger")
@@ -581,7 +592,7 @@ class ExceptionHandlingTest < ActiveSupport::TestCase
581
592
  parameters = { advertiser_id: 435, controller: "some_controller" }
582
593
  session = { username: "jsmith" }
583
594
  request_uri = "host/path"
584
- controller = create_dummy_controller(env, parameters, session, request_uri)
595
+ ExceptionHandling.current_controller = create_dummy_controller(env, parameters, session, request_uri)
585
596
  stub(ExceptionHandling).server_name { "invoca_fe98" }
586
597
 
587
598
  exception = StandardError.new("Some Exception")
@@ -595,7 +606,7 @@ class ExceptionHandlingTest < ActiveSupport::TestCase
595
606
  mock(Honeybadger).notify.with_any_args do |data|
596
607
  honeybadger_data = data
597
608
  end
598
- ExceptionHandling.log_error(exception, exception_context, controller) do |data|
609
+ ExceptionHandling.log_error(exception, exception_context) do |data|
599
610
  data[:scm_revision] = "5b24eac37aaa91f5784901e9aabcead36fd9df82"
600
611
  data[:user_details] = { username: "jsmith" }
601
612
  data[:event_response] = "Event successfully received"
@@ -1042,10 +1053,10 @@ class ExceptionHandlingTest < ActiveSupport::TestCase
1042
1053
  Time.now_override = nil
1043
1054
  end
1044
1055
 
1045
- should "take in additional key word args as logging context and pass them to the logger" do
1056
+ should "take in additional logging context and pass them to the logger" do
1046
1057
  ExceptionHandling.log_periodically(:test_context_with_periodic, 30.minutes, "this will be written", service_name: 'exception_handling')
1047
1058
  assert_not_empty logged_excluding_reload_filter.last[:context]
1048
- assert_equal logged_excluding_reload_filter.last[:context], service_name: 'exception_handling'
1059
+ assert_equal({ service_name: 'exception_handling' }, logged_excluding_reload_filter.last[:context])
1049
1060
  end
1050
1061
 
1051
1062
  should "log immediately when we are expected to log" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exception_handling
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.4.0.pre.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Colin Kelley
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-05 00:00:00.000000000 Z
11
+ date: 2020-02-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionmailer
@@ -154,7 +154,9 @@ files:
154
154
  - views/exception_handling/mailer/log_parser_exception_notification.html.erb
155
155
  homepage: https://github.com/Invoca/exception_handling
156
156
  licenses: []
157
- metadata: {}
157
+ metadata:
158
+ source_code_uri: https://github.com/Invoca/exception_handling
159
+ allowed_push_host: https://rubygems.org
158
160
  post_install_message:
159
161
  rdoc_options: []
160
162
  require_paths:
@@ -166,9 +168,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
166
168
  version: '0'
167
169
  required_rubygems_version: !ruby/object:Gem::Requirement
168
170
  requirements:
169
- - - ">="
171
+ - - ">"
170
172
  - !ruby/object:Gem::Version
171
- version: '0'
173
+ version: 1.3.1
172
174
  requirements: []
173
175
  rubyforge_project:
174
176
  rubygems_version: 2.6.13