exception_handling 2.4.3.pre.1 → 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 +4 -4
- data/CHANGELOG.md +7 -1
- data/Gemfile.lock +7 -7
- data/Rakefile +2 -0
- data/exception_handling.gemspec +6 -6
- data/lib/exception_handling.rb +4 -2
- data/lib/exception_handling/exception_info.rb +7 -4
- data/lib/exception_handling/version.rb +1 -1
- data/test/unit/exception_handling/exception_info_test.rb +15 -15
- data/test/unit/exception_handling/honeybadger_callbacks_test.rb +1 -1
- data/test/unit/exception_handling_test.rb +4 -2
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 267155818260bd0971adcfb3f325ce559c70b47fd362a8f80a2f92fc81117bf7
|
4
|
+
data.tar.gz: 52532fdf7184f79c85bbd384340ce99d753cd3b964ea9e1808da77091c5827b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf6315b8cf9c5bf2d1bae4732571ee0cc4609e57179c0935775b2b7435ebc44739ed3f61eb84f35adc22a59a7f643892f392f4d2e069ef672a17aa23c1753a67
|
7
|
+
data.tar.gz: d61c96173c88073a5be405480aeadd9a997749bc0b811534abe9b549c281f07b64e096123822a8268c0deb78f8eff139debd4ed93f78576305ae3ebc9e533cc8
|
data/CHANGELOG.md
CHANGED
@@ -4,7 +4,12 @@ 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.
|
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: ... }`.
|
11
|
+
|
12
|
+
## [2.4.3] - 2020-05-14
|
8
13
|
### Deprecated
|
9
14
|
- In `ExceptionHandling.logger=`, implicit `logger.extend ContextualLogger::LoggerMixin` is now deprecated.
|
10
15
|
This will be removed in version 3.0 and an `ArgumentError` will be raised if the logger
|
@@ -24,6 +29,7 @@ Note: this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0
|
|
24
29
|
### Changed
|
25
30
|
- No longer depends on hobo_support. Uses invoca-utils 0.3 instead.
|
26
31
|
|
32
|
+
[2.5.0]: https://github.com/Invoca/exception_handling/compare/v2.4.3...v2.5.0
|
27
33
|
[2.4.3]: https://github.com/Invoca/exception_handling/compare/v2.4.2...v2.4.3
|
28
34
|
[2.4.2]: https://github.com/Invoca/exception_handling/compare/v2.4.1...v2.4.2
|
29
35
|
[2.4.1]: https://github.com/Invoca/exception_handling/compare/v2.4.0...v2.4.1
|
data/Gemfile.lock
CHANGED
@@ -8,11 +8,11 @@ GIT
|
|
8
8
|
PATH
|
9
9
|
remote: .
|
10
10
|
specs:
|
11
|
-
exception_handling (2.
|
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)
|
15
|
-
contextual_logger
|
15
|
+
contextual_logger (~> 0.7)
|
16
16
|
eventmachine (~> 1.0)
|
17
17
|
invoca-utils (~> 0.3)
|
18
18
|
|
@@ -55,7 +55,7 @@ GEM
|
|
55
55
|
builder (3.2.3)
|
56
56
|
coderay (1.1.2)
|
57
57
|
concurrent-ruby (1.1.5)
|
58
|
-
contextual_logger (0.
|
58
|
+
contextual_logger (0.8.0)
|
59
59
|
activesupport
|
60
60
|
json
|
61
61
|
crass (1.0.6)
|
@@ -65,10 +65,10 @@ GEM
|
|
65
65
|
activesupport (>= 4.2.0)
|
66
66
|
i18n (0.9.5)
|
67
67
|
concurrent-ruby (~> 1.0)
|
68
|
-
invoca-utils (0.
|
68
|
+
invoca-utils (0.4.1)
|
69
69
|
jaro_winkler (1.5.3)
|
70
|
-
json (2.3.
|
71
|
-
loofah (2.
|
70
|
+
json (2.3.1)
|
71
|
+
loofah (2.6.0)
|
72
72
|
crass (~> 1.0.2)
|
73
73
|
nokogiri (>= 1.5.9)
|
74
74
|
mail (2.7.1)
|
@@ -82,7 +82,7 @@ GEM
|
|
82
82
|
builder
|
83
83
|
minitest (>= 5.0)
|
84
84
|
ruby-progressbar
|
85
|
-
nokogiri (1.10.
|
85
|
+
nokogiri (1.10.10)
|
86
86
|
mini_portile2 (~> 2.4.0)
|
87
87
|
parallel (1.17.0)
|
88
88
|
parser (2.6.3.0)
|
data/Rakefile
CHANGED
data/exception_handling.gemspec
CHANGED
@@ -20,10 +20,10 @@ Gem::Specification.new do |spec|
|
|
20
20
|
"allowed_push_host" => "https://rubygems.org"
|
21
21
|
}
|
22
22
|
|
23
|
-
spec.add_dependency 'actionmailer',
|
24
|
-
spec.add_dependency 'actionpack',
|
25
|
-
spec.add_dependency 'activesupport',
|
26
|
-
spec.add_dependency 'contextual_logger'
|
27
|
-
spec.add_dependency 'eventmachine',
|
28
|
-
spec.add_dependency 'invoca-utils',
|
23
|
+
spec.add_dependency 'actionmailer', '>= 4.2', '< 7.0'
|
24
|
+
spec.add_dependency 'actionpack', '>= 4.2', '< 7.0'
|
25
|
+
spec.add_dependency 'activesupport', '>= 4.2', '< 7.0'
|
26
|
+
spec.add_dependency 'contextual_logger', '~> 0.7'
|
27
|
+
spec.add_dependency 'eventmachine', '~> 1.0'
|
28
|
+
spec.add_dependency 'invoca-utils', '~> 0.3'
|
29
29
|
end
|
data/lib/exception_handling.rb
CHANGED
@@ -60,7 +60,7 @@ module ExceptionHandling # never included
|
|
60
60
|
@logger = if logger.is_a?(ContextualLogger::LoggerMixin)
|
61
61
|
logger
|
62
62
|
else
|
63
|
-
Deprecation3_0.deprecation_warning('implicit extend with ContextualLogger::LoggerMixin', 'extend your logger instance or include
|
63
|
+
Deprecation3_0.deprecation_warning('implicit extend with ContextualLogger::LoggerMixin', 'extend your logger instance or include into your logger class first')
|
64
64
|
logger.extend(ContextualLogger::LoggerMixin)
|
65
65
|
end
|
66
66
|
end
|
@@ -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,
|
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
|
-
|
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,
|
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
|
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) &&
|
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?
|
@@ -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,
|
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,
|
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,
|
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,
|
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,
|
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,
|
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,
|
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
|
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
|
@@ -636,7 +636,8 @@ class ExceptionHandlingTest < ActiveSupport::TestCase
|
|
636
636
|
mock(Honeybadger).notify.with_any_args do |data|
|
637
637
|
honeybadger_data = data
|
638
638
|
end
|
639
|
-
|
639
|
+
log_context = { log_source: "gem/listen", cuid: "AA12BC34DE" }
|
640
|
+
ExceptionHandling.log_error(exception, exception_context, controller, **log_context) do |data|
|
640
641
|
data[:scm_revision] = "5b24eac37aaa91f5784901e9aabcead36fd9df82"
|
641
642
|
data[:user_details] = { username: "jsmith" }
|
642
643
|
data[:event_response] = "Event successfully received"
|
@@ -672,7 +673,8 @@ class ExceptionHandlingTest < ActiveSupport::TestCase
|
|
672
673
|
"test/unit/exception_handling_test.rb:847:in `exception_1'",
|
673
674
|
"test/unit/exception_handling_test.rb:455:in `block (4 levels) in <class:ExceptionHandlingTest>'"
|
674
675
|
],
|
675
|
-
event_response: "Event successfully received"
|
676
|
+
event_response: "Event successfully received",
|
677
|
+
log_context: { "log_source" => "gem/listen", "cuid" => "AA12BC34DE" }
|
676
678
|
}
|
677
679
|
}
|
678
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
|
+
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-
|
11
|
+
date: 2020-08-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionmailer
|
@@ -74,16 +74,16 @@ dependencies:
|
|
74
74
|
name: contextual_logger
|
75
75
|
requirement: !ruby/object:Gem::Requirement
|
76
76
|
requirements:
|
77
|
-
- - "
|
77
|
+
- - "~>"
|
78
78
|
- !ruby/object:Gem::Version
|
79
|
-
version: '0'
|
79
|
+
version: '0.7'
|
80
80
|
type: :runtime
|
81
81
|
prerelease: false
|
82
82
|
version_requirements: !ruby/object:Gem::Requirement
|
83
83
|
requirements:
|
84
|
-
- - "
|
84
|
+
- - "~>"
|
85
85
|
- !ruby/object:Gem::Version
|
86
|
-
version: '0'
|
86
|
+
version: '0.7'
|
87
87
|
- !ruby/object:Gem::Dependency
|
88
88
|
name: eventmachine
|
89
89
|
requirement: !ruby/object:Gem::Requirement
|