exception_handling 2.4.4 → 2.5.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
  SHA256:
3
- metadata.gz: de262141b33b7c4cb5e68018569d0465144097e36d0b85c268646cb0bfb5eb3f
4
- data.tar.gz: cdbd41bfd1df237f6d6c3c1788ac52a0ed75314c5fbf63b3cb549edc21aeb3ed
3
+ metadata.gz: 267155818260bd0971adcfb3f325ce559c70b47fd362a8f80a2f92fc81117bf7
4
+ data.tar.gz: 52532fdf7184f79c85bbd384340ce99d753cd3b964ea9e1808da77091c5827b1
5
5
  SHA512:
6
- metadata.gz: a64db1560f94c6c62ced1d7b5afadd1ece6618ee62e41db250b2384e8193b29ec35e39b9389edb2a1e130b2aebf77b4e7851b8173a705b8a7b620284f62e1b9e
7
- data.tar.gz: c2efcf1378cf70651ccd1e2e4f3f0f85ff4fe49714f7547d3b4517a0afb1c657f7a8def9dd4339aa7bd510fc714d53b27cc7120fe109fa12eea2c8bbfe98de6e
6
+ metadata.gz: cf6315b8cf9c5bf2d1bae4732571ee0cc4609e57179c0935775b2b7435ebc44739ed3f61eb84f35adc22a59a7f643892f392f4d2e069ef672a17aa23c1753a67
7
+ data.tar.gz: d61c96173c88073a5be405480aeadd9a997749bc0b811534abe9b549c281f07b64e096123822a8268c0deb78f8eff139debd4ed93f78576305ae3ebc9e533cc8
@@ -4,9 +4,10 @@ Inspired by [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
4
4
 
5
5
  Note: this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
- ## [2.4.4] - 2020-08-10
8
- ### Fixed
9
- - `ExceptionHandling.logger = nil` no longer displays an "implicit extend" deprecation warning.
7
+ ## [2.5.0] - Unreleased
8
+ ### Added
9
+ - The `**log_context` passed to `log_error`/`log_warning`/`log_info` is now
10
+ passed into `Honeybadger.notify()`, in `context: { log_context: ... }`.
10
11
 
11
12
  ## [2.4.3] - 2020-05-14
12
13
  ### Deprecated
@@ -28,7 +29,7 @@ Note: this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0
28
29
  ### Changed
29
30
  - No longer depends on hobo_support. Uses invoca-utils 0.3 instead.
30
31
 
31
- [2.4.3]: https://github.com/Invoca/exception_handling/compare/v2.4.3...v2.4.4
32
+ [2.5.0]: https://github.com/Invoca/exception_handling/compare/v2.4.3...v2.5.0
32
33
  [2.4.3]: https://github.com/Invoca/exception_handling/compare/v2.4.2...v2.4.3
33
34
  [2.4.2]: https://github.com/Invoca/exception_handling/compare/v2.4.1...v2.4.2
34
35
  [2.4.1]: https://github.com/Invoca/exception_handling/compare/v2.4.0...v2.4.1
@@ -8,7 +8,7 @@ GIT
8
8
  PATH
9
9
  remote: .
10
10
  specs:
11
- exception_handling (2.4.4)
11
+ exception_handling (2.5.0.pre.1)
12
12
  actionmailer (>= 4.2, < 7.0)
13
13
  actionpack (>= 4.2, < 7.0)
14
14
  activesupport (>= 4.2, < 7.0)
data/Rakefile CHANGED
@@ -4,6 +4,8 @@
4
4
  require "bundler/gem_tasks"
5
5
  require 'rake/testtask'
6
6
 
7
+ require_relative 'test/rake_test_warning_false'
8
+
7
9
  task default: :test
8
10
 
9
11
  Rake::TestTask.new do |t|
@@ -57,7 +57,7 @@ module ExceptionHandling # never included
57
57
  Deprecation3_0 = ActiveSupport::Deprecation.new('3.0', 'exception_handling')
58
58
 
59
59
  def logger=(logger)
60
- @logger = if logger.nil? || logger.is_a?(ContextualLogger::LoggerMixin)
60
+ @logger = if logger.is_a?(ContextualLogger::LoggerMixin)
61
61
  logger
62
62
  else
63
63
  Deprecation3_0.deprecation_warning('implicit extend with ContextualLogger::LoggerMixin', 'extend your logger instance or include into your logger class first')
@@ -193,7 +193,9 @@ module ExceptionHandling # never included
193
193
  def log_error(exception_or_string, exception_context = '', controller = nil, treat_like_warning: false, **log_context, &data_callback)
194
194
  ex = make_exception(exception_or_string)
195
195
  timestamp = set_log_error_timestamp
196
- exception_info = ExceptionInfo.new(ex, exception_context, timestamp, controller || current_controller, data_callback)
196
+ exception_info = ExceptionInfo.new(ex, exception_context, timestamp,
197
+ controller: controller || current_controller, data_callback: data_callback,
198
+ log_context: log_context)
197
199
 
198
200
  if stub_handler
199
201
  stub_handler.handle_stub_log_error(exception_info.data)
@@ -3,7 +3,7 @@
3
3
  module ExceptionHandling
4
4
  class ExceptionInfo
5
5
 
6
- ENVIRONMENT_WHITELIST = [
6
+ ENVIRONMENT_ALLOWLIST = [
7
7
  /^HTTP_/,
8
8
  /^QUERY_/,
9
9
  /^REQUEST_/,
@@ -46,16 +46,18 @@ module ExceptionHandling
46
46
  EOS
47
47
 
48
48
  SECTIONS = [:request, :session, :environment, :backtrace, :event_response].freeze
49
- HONEYBADGER_CONTEXT_SECTIONS = [:timestamp, :error_class, :exception_context, :server, :scm_revision, :notes, :user_details, :request, :session, :environment, :backtrace, :event_response].freeze
49
+ HONEYBADGER_CONTEXT_SECTIONS = [:timestamp, :error_class, :exception_context, :server, :scm_revision, :notes,
50
+ :user_details, :request, :session, :environment, :backtrace, :event_response, :log_context].freeze
50
51
 
51
52
  attr_reader :exception, :controller, :exception_context, :timestamp
52
53
 
53
- def initialize(exception, exception_context, timestamp, controller = nil, data_callback = nil)
54
+ def initialize(exception, exception_context, timestamp, controller: nil, data_callback: nil, log_context: nil)
54
55
  @exception = exception
55
56
  @exception_context = exception_context
56
57
  @timestamp = timestamp
57
58
  @controller = controller || controller_from_context(exception_context)
58
59
  @data_callback = data_callback
60
+ @log_context = log_context
59
61
  end
60
62
 
61
63
  def data
@@ -176,7 +178,7 @@ module ExceptionHandling
176
178
 
177
179
  def clean_environment(env)
178
180
  Hash[ env.map do |k, v|
179
- [k, v] if !"#{k}: #{v}".in?(ENVIRONMENT_OMIT) && ENVIRONMENT_WHITELIST.any? { |regex| k =~ regex }
181
+ [k, v] if !"#{k}: #{v}".in?(ENVIRONMENT_OMIT) && ENVIRONMENT_ALLOWLIST.any? { |regex| k =~ regex }
180
182
  end.compact ]
181
183
  end
182
184
 
@@ -267,6 +269,7 @@ module ExceptionHandling
267
269
  data = enhanced_data.dup
268
270
  data[:server] = ExceptionHandling.server_name
269
271
  data[:exception_context] = deep_clean_hash(@exception_context) if @exception_context.present?
272
+ data[:log_context] = @log_context
270
273
  unstringify_sections(data)
271
274
  context_data = HONEYBADGER_CONTEXT_SECTIONS.reduce({}) do |context, section|
272
275
  if data[section].present?
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ExceptionHandling
4
- VERSION = '2.4.4'
4
+ VERSION = '2.5.0.pre.1'
5
5
  end
@@ -29,7 +29,7 @@ module ExceptionHandling
29
29
  exception_context = {
30
30
  "action_controller.instance" => Object.new
31
31
  }
32
- exception_info = ExceptionInfo.new(@exception, exception_context, @timestamp, @controller)
32
+ exception_info = ExceptionInfo.new(@exception, exception_context, @timestamp, controller: @controller)
33
33
  assert_equal @controller, exception_info.controller
34
34
  assert_not_equal exception_context["action_controller.instance"], exception_info.controller
35
35
  end
@@ -107,7 +107,7 @@ module ExceptionHandling
107
107
  request_uri = "host/path"
108
108
  controller = create_dummy_controller(env, parameters, session, request_uri)
109
109
  data_callback = ->(data) { data[:custom_section] = "value" }
110
- exception_info = ExceptionInfo.new(@exception, "custom context data", @timestamp, controller, data_callback)
110
+ exception_info = ExceptionInfo.new(@exception, "custom context data", @timestamp, controller: controller, data_callback: data_callback)
111
111
 
112
112
  dont_allow(exception_info).extract_and_merge_controller_data
113
113
  dont_allow(exception_info).customize_from_data_callback
@@ -177,7 +177,7 @@ module ExceptionHandling
177
177
  end
178
178
 
179
179
  should "include controller data when available" do
180
- exception_info = ExceptionInfo.new(@exception, @exception_context, @timestamp, @controller)
180
+ exception_info = ExceptionInfo.new(@exception, @exception_context, @timestamp, controller: @controller)
181
181
  expected_data = {
182
182
  "error_class" => "StandardError",
183
183
  "error_string" => "StandardError: something went wrong",
@@ -220,7 +220,7 @@ module ExceptionHandling
220
220
  end
221
221
 
222
222
  should "add to_s attribute to specific sections that have their content in hash format" do
223
- exception_info = ExceptionInfo.new(@exception, @exception_context, @timestamp, @controller)
223
+ exception_info = ExceptionInfo.new(@exception, @exception_context, @timestamp, controller: @controller)
224
224
  expected_data = {
225
225
  "error_class" => "StandardError",
226
226
  "error_string" => "StandardError: something went wrong",
@@ -251,7 +251,7 @@ module ExceptionHandling
251
251
  should "filter out sensitive parameters like passwords" do
252
252
  @controller.request.parameters[:password] = "super_secret"
253
253
  @controller.request.parameters[:user] = { "password" => "also super secret", "password_confirmation" => "also super secret" }
254
- exception_info = ExceptionInfo.new(@exception, @exception_context, @timestamp, @controller)
254
+ exception_info = ExceptionInfo.new(@exception, @exception_context, @timestamp, controller: @controller)
255
255
  expected_params = {
256
256
  "password" => "[FILTERED]",
257
257
  "advertiser_id" => 435, "controller" => "dummy",
@@ -265,7 +265,7 @@ module ExceptionHandling
265
265
  end
266
266
 
267
267
  should "include the changes from the custom data callback" do
268
- exception_info = ExceptionInfo.new(@exception, @exception_context, @timestamp, nil, @data_callback)
268
+ exception_info = ExceptionInfo.new(@exception, @exception_context, @timestamp, controller: nil, data_callback: @data_callback)
269
269
  expected_data = {
270
270
  "error_class" => "StandardError",
271
271
  "error_string" => "StandardError: something went wrong",
@@ -331,7 +331,7 @@ module ExceptionHandling
331
331
  request_uri = "host/path"
332
332
  controller = create_dummy_controller(env, parameters, session, request_uri)
333
333
  exception = StandardError.new("Request to click domain rejected")
334
- exception_info = ExceptionInfo.new(exception, {}, Time.now, controller)
334
+ exception_info = ExceptionInfo.new(exception, nil, Time.now, controller: controller)
335
335
  assert_equal true, exception_info.enhanced_data[:request].is_a?(Hash)
336
336
  description = exception_info.exception_description
337
337
  assert_not_nil description
@@ -340,11 +340,11 @@ module ExceptionHandling
340
340
 
341
341
  should "return same description object for related errors (avoid reloading exception catalog from disk)" do
342
342
  exception = StandardError.new("No route matches")
343
- exception_info = ExceptionInfo.new(exception, {}, Time.now)
343
+ exception_info = ExceptionInfo.new(exception, nil, Time.now)
344
344
  description = exception_info.exception_description
345
345
 
346
346
  repeat_ex = StandardError.new("No route matches 2")
347
- repeat_ex_info = ExceptionInfo.new(repeat_ex, {}, Time.now)
347
+ repeat_ex_info = ExceptionInfo.new(repeat_ex, nil, Time.now)
348
348
  assert_equal description.object_id, repeat_ex_info.exception_description.object_id
349
349
  end
350
350
  end
@@ -368,7 +368,7 @@ module ExceptionHandling
368
368
  session = { username: 'smith' }
369
369
  request_uri = "host/path"
370
370
  controller = create_dummy_controller(env, parameters, session, request_uri)
371
- exception_info = ExceptionInfo.new(@exception, @exception_context, @timestamp, controller)
371
+ exception_info = ExceptionInfo.new(@exception, @exception_context, @timestamp, controller: controller)
372
372
 
373
373
  assert_equal 'some_controller', exception_info.controller_name
374
374
  end
@@ -384,7 +384,7 @@ module ExceptionHandling
384
384
  should "be enabled when Honeybadger is defined and exception is not in the filter list" do
385
385
  stub(ExceptionHandling).honeybadger_defined? { true }
386
386
  exception = StandardError.new("something went wrong")
387
- exception_info = ExceptionInfo.new(exception, {}, Time.now)
387
+ exception_info = ExceptionInfo.new(exception, nil, Time.now)
388
388
  assert_nil exception_info.exception_description
389
389
  assert_equal true, exception_info.send_to_honeybadger?
390
390
  end
@@ -392,7 +392,7 @@ module ExceptionHandling
392
392
  should "be enabled when Honeybadger is defined and exception is on the filter list with the flag turned on" do
393
393
  stub(ExceptionHandling).honeybadger_defined? { true }
394
394
  exception = StandardError.new("No route matches")
395
- exception_info = ExceptionInfo.new(exception, {}, Time.now)
395
+ exception_info = ExceptionInfo.new(exception, nil, Time.now)
396
396
  assert_not_nil exception_info.exception_description
397
397
  assert_equal true, exception_info.exception_description.send_to_honeybadger
398
398
  assert_equal true, exception_info.send_to_honeybadger?
@@ -401,7 +401,7 @@ module ExceptionHandling
401
401
  should "be disabled when Honeybadger is defined and exception is on the filter list with the flag turned off" do
402
402
  stub(ExceptionHandling).honeybadger_defined? { true }
403
403
  exception = StandardError.new("No route matches")
404
- exception_info = ExceptionInfo.new(exception, {}, Time.now)
404
+ exception_info = ExceptionInfo.new(exception, nil, Time.now)
405
405
  assert_not_nil exception_info.exception_description
406
406
  stub(exception_info.exception_description).send_to_honeybadger { false }
407
407
  assert_equal false, exception_info.send_to_honeybadger?
@@ -410,7 +410,7 @@ module ExceptionHandling
410
410
  should "be disabled when Honeybadger is not defined" do
411
411
  stub(ExceptionHandling).honeybadger_defined? { false }
412
412
  exception = StandardError.new("something went wrong")
413
- exception_info = ExceptionInfo.new(exception, {}, Time.now)
413
+ exception_info = ExceptionInfo.new(exception, nil, Time.now)
414
414
  assert_nil exception_info.exception_description
415
415
  assert_equal false, exception_info.send_to_honeybadger?
416
416
  end
@@ -438,7 +438,7 @@ module ExceptionHandling
438
438
  data[:other_section] = "This should not be included in the response"
439
439
  end
440
440
  timestamp = Time.now
441
- exception_info = ExceptionInfo.new(exception, exception_context, timestamp, controller, data_callback)
441
+ exception_info = ExceptionInfo.new(exception, exception_context, timestamp, controller: controller, data_callback: data_callback)
442
442
 
443
443
  expected_data = {
444
444
  timestamp: timestamp,
@@ -95,7 +95,7 @@ module ExceptionHandling
95
95
  assert_equal "#<ExceptionHandling::HoneybadgerCallbacksTest::TestRaiseOnInspectWithId @id=123 [error 'RuntimeError: some error' while calling #inspect]>", result
96
96
  end
97
97
 
98
- should "handle exceptions for objects responding to to_pik" do
98
+ should "handle exceptions for objects responding to to_pk" do
99
99
  result = HoneybadgerCallbacks.send(:local_variable_filter, :variable_name, TestRaiseOnInspectWithToPk.new, ['password'])
100
100
  assert_equal "#<ExceptionHandling::HoneybadgerCallbacksTest::TestRaiseOnInspectWithToPk @pk=SomeRecord-123 [error 'RuntimeError: some error' while calling #inspect]>", result
101
101
  end
@@ -126,11 +126,6 @@ class ExceptionHandlingTest < ActiveSupport::TestCase
126
126
  assert_equal ancestors, ExceptionHandling.logger.singleton_class.ancestors.*.name
127
127
  end
128
128
 
129
- should "allow logger = nil (no deprecation warning)" do
130
- mock(STDERR).puts(/DEPRECATION WARNING/).never
131
- ExceptionHandling.logger = nil
132
- end
133
-
134
129
  should "[deprecated] mix in ContextualLogger::Mixin if not there" do
135
130
  mock(STDERR).puts(/DEPRECATION WARNING: implicit extend with ContextualLogger::LoggerMixin is deprecated and will be removed from exception_handling 3\.0/)
136
131
  logger = Logger.new('/dev/null')
@@ -641,7 +636,8 @@ class ExceptionHandlingTest < ActiveSupport::TestCase
641
636
  mock(Honeybadger).notify.with_any_args do |data|
642
637
  honeybadger_data = data
643
638
  end
644
- ExceptionHandling.log_error(exception, exception_context, controller) do |data|
639
+ log_context = { log_source: "gem/listen", cuid: "AA12BC34DE" }
640
+ ExceptionHandling.log_error(exception, exception_context, controller, **log_context) do |data|
645
641
  data[:scm_revision] = "5b24eac37aaa91f5784901e9aabcead36fd9df82"
646
642
  data[:user_details] = { username: "jsmith" }
647
643
  data[:event_response] = "Event successfully received"
@@ -677,7 +673,8 @@ class ExceptionHandlingTest < ActiveSupport::TestCase
677
673
  "test/unit/exception_handling_test.rb:847:in `exception_1'",
678
674
  "test/unit/exception_handling_test.rb:455:in `block (4 levels) in <class:ExceptionHandlingTest>'"
679
675
  ],
680
- event_response: "Event successfully received"
676
+ event_response: "Event successfully received",
677
+ log_context: { "log_source" => "gem/listen", "cuid" => "AA12BC34DE" }
681
678
  }
682
679
  }
683
680
  assert_equal_with_diff expected_data, honeybadger_data
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.4.4
4
+ version: 2.5.0.pre.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Invoca
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-11 00:00:00.000000000 Z
11
+ date: 2020-08-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionmailer
@@ -179,9 +179,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
179
179
  version: '0'
180
180
  required_rubygems_version: !ruby/object:Gem::Requirement
181
181
  requirements:
182
- - - ">="
182
+ - - ">"
183
183
  - !ruby/object:Gem::Version
184
- version: '0'
184
+ version: 1.3.1
185
185
  requirements: []
186
186
  rubygems_version: 3.0.3
187
187
  signing_key: