exception_handling 2.4.3.pre.2 → 2.5.0.pre.2
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 +12 -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/rake_test_warning_false.rb +20 -0
- 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 +117 -56
- metadata +8 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e1f2be68af4ed35506d1ecb517eb720a197a4d3c7d346eeb11c87d8a6e9abdf5
|
4
|
+
data.tar.gz: c87a3341b654ae7144f41888fc0e454953f52663a259f353405790c25d8596ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d2b5d03154666523f7fe03321ad1d1fa28ac0ae00629249c21f9f73a330b6f325acfe1ce8b039df4f318b6ade3dd28373b476f87f12d46917016403fbc8a8d6
|
7
|
+
data.tar.gz: 1482537c680996153dd63c7edb30b43259789a16ff3f86b8a61b5cd8aab402a9c07905dbc7d0a945ea0b93fd0fea2ea3ec09bbe51b389fe440d9d58991f08bb9
|
data/CHANGELOG.md
CHANGED
@@ -4,7 +4,16 @@ 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.4] - 2020-08-10
|
13
|
+
### Fixed
|
14
|
+
- `ExceptionHandling.logger = nil` no longer displays an "implicit extend" deprecation warning.
|
15
|
+
|
16
|
+
## [2.4.3] - 2020-05-14
|
8
17
|
### Deprecated
|
9
18
|
- In `ExceptionHandling.logger=`, implicit `logger.extend ContextualLogger::LoggerMixin` is now deprecated.
|
10
19
|
This will be removed in version 3.0 and an `ArgumentError` will be raised if the logger
|
@@ -24,6 +33,8 @@ Note: this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0
|
|
24
33
|
### Changed
|
25
34
|
- No longer depends on hobo_support. Uses invoca-utils 0.3 instead.
|
26
35
|
|
36
|
+
[2.5.0]: https://github.com/Invoca/exception_handling/compare/v2.4.4...v2.5.0
|
37
|
+
[2.4.4]: https://github.com/Invoca/exception_handling/compare/v2.4.3...v2.4.4
|
27
38
|
[2.4.3]: https://github.com/Invoca/exception_handling/compare/v2.4.2...v2.4.3
|
28
39
|
[2.4.2]: https://github.com/Invoca/exception_handling/compare/v2.4.1...v2.4.2
|
29
40
|
[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.2)
|
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.9.1)
|
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
@@ -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.is_a?(ContextualLogger::LoggerMixin)
|
60
|
+
@logger = if logger.nil? || 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,
|
196
|
+
exception_info = ExceptionInfo.new(ex, exception_context, timestamp,
|
197
|
+
controller: controller || current_controller, data_callback: data_callback,
|
198
|
+
log_context: logger.current_context_for_thread.deep_merge(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?
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Rake 11+ has a misfeature where @warning = true by default
|
4
|
+
# See https://github.com/ruby/rake/pull/97/files
|
5
|
+
# This causes all tests to be run with `ruby -w`, causing a huge number of warnings
|
6
|
+
# from gems we don't control and overwhelming our test output.
|
7
|
+
# This patch reverts that.
|
8
|
+
|
9
|
+
_ = Rake::TestTask
|
10
|
+
|
11
|
+
class Rake::TestTask
|
12
|
+
module SetWarningFalseMixin
|
13
|
+
def initialize(*args)
|
14
|
+
super
|
15
|
+
self.warning = false
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
prepend SetWarningFalseMixin
|
20
|
+
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,
|
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
|
@@ -126,6 +126,11 @@ 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
|
+
|
129
134
|
should "[deprecated] mix in ContextualLogger::Mixin if not there" do
|
130
135
|
mock(STDERR).puts(/DEPRECATION WARNING: implicit extend with ContextualLogger::LoggerMixin is deprecated and will be removed from exception_handling 3\.0/)
|
131
136
|
logger = Logger.new('/dev/null')
|
@@ -616,66 +621,122 @@ class ExceptionHandlingTest < ActiveSupport::TestCase
|
|
616
621
|
ExceptionHandling.log_error(exception_with_nil_message)
|
617
622
|
end
|
618
623
|
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
honeybadger_data = nil
|
636
|
-
mock(Honeybadger).notify.with_any_args do |data|
|
637
|
-
honeybadger_data = data
|
624
|
+
context "with stubbed values" do
|
625
|
+
setup do
|
626
|
+
Time.now_override = Time.now
|
627
|
+
@env = { server: "fe98" }
|
628
|
+
@parameters = { advertiser_id: 435, controller: "some_controller" }
|
629
|
+
@session = { username: "jsmith" }
|
630
|
+
@request_uri = "host/path"
|
631
|
+
@controller = create_dummy_controller(@env, @parameters, @session, @request_uri)
|
632
|
+
stub(ExceptionHandling).server_name { "invoca_fe98" }
|
633
|
+
|
634
|
+
@exception = StandardError.new("Some Exception")
|
635
|
+
@exception.set_backtrace([
|
636
|
+
"test/unit/exception_handling_test.rb:847:in `exception_1'",
|
637
|
+
"test/unit/exception_handling_test.rb:455:in `block (4 levels) in <class:ExceptionHandlingTest>'"
|
638
|
+
])
|
639
|
+
@exception_context = { "SERVER_NAME" => "exceptional.com" }
|
638
640
|
end
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
641
|
+
|
642
|
+
should "send error details and relevant context data to Honeybadger with log_context" do
|
643
|
+
honeybadger_data = nil
|
644
|
+
mock(Honeybadger).notify.with_any_args do |data|
|
645
|
+
honeybadger_data = data
|
646
|
+
end
|
647
|
+
ExceptionHandling.logger.global_context = { service_name: "rails", region: "AWS-us-east-1" }
|
648
|
+
log_context = { log_source: "gem/listen", service_name: "bin/console" }
|
649
|
+
ExceptionHandling.log_error(@exception, @exception_context, @controller, **log_context) do |data|
|
650
|
+
data[:scm_revision] = "5b24eac37aaa91f5784901e9aabcead36fd9df82"
|
651
|
+
data[:user_details] = { username: "jsmith" }
|
652
|
+
data[:event_response] = "Event successfully received"
|
653
|
+
data[:other_section] = "This should not be included in the response"
|
654
|
+
end
|
655
|
+
|
656
|
+
expected_data = {
|
657
|
+
error_class: :"Test Exception",
|
658
|
+
error_message: "Some Exception",
|
659
|
+
controller: "some_controller",
|
660
|
+
exception: @exception,
|
661
|
+
context: {
|
662
|
+
timestamp: Time.now.to_i,
|
663
|
+
error_class: "StandardError",
|
664
|
+
server: "invoca_fe98",
|
665
|
+
exception_context: { "SERVER_NAME" => "exceptional.com" },
|
666
|
+
scm_revision: "5b24eac37aaa91f5784901e9aabcead36fd9df82",
|
667
|
+
notes: "this is used by a test",
|
668
|
+
user_details: { "username" => "jsmith" },
|
669
|
+
request: {
|
670
|
+
"params" => { "advertiser_id" => 435, "controller" => "some_controller" },
|
671
|
+
"rails_root" => "Rails.root not defined. Is this a test environment?",
|
672
|
+
"url" => "host/path"
|
673
|
+
},
|
674
|
+
session: {
|
675
|
+
"key" => nil,
|
676
|
+
"data" => { "username" => "jsmith" }
|
677
|
+
},
|
678
|
+
environment: {
|
679
|
+
"SERVER_NAME" => "exceptional.com"
|
680
|
+
},
|
681
|
+
backtrace: [
|
682
|
+
"test/unit/exception_handling_test.rb:847:in `exception_1'",
|
683
|
+
"test/unit/exception_handling_test.rb:455:in `block (4 levels) in <class:ExceptionHandlingTest>'"
|
684
|
+
],
|
685
|
+
event_response: "Event successfully received",
|
686
|
+
log_context: { "service_name" => "bin/console", "region" => "AWS-us-east-1", "log_source" => "gem/listen" }
|
687
|
+
}
|
688
|
+
}
|
689
|
+
assert_equal_with_diff expected_data, honeybadger_data
|
644
690
|
end
|
645
691
|
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
"SERVER_NAME" => "exceptional.com"
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
692
|
+
should "send error details and relevant context data to Honeybadger with empty log_context" do
|
693
|
+
honeybadger_data = nil
|
694
|
+
mock(Honeybadger).notify.with_any_args do |data|
|
695
|
+
honeybadger_data = data
|
696
|
+
end
|
697
|
+
ExceptionHandling.logger.global_context = {}
|
698
|
+
log_context = {}
|
699
|
+
ExceptionHandling.log_error(@exception, @exception_context, @controller, **log_context) do |data|
|
700
|
+
data[:scm_revision] = "5b24eac37aaa91f5784901e9aabcead36fd9df82"
|
701
|
+
data[:user_details] = { username: "jsmith" }
|
702
|
+
data[:event_response] = "Event successfully received"
|
703
|
+
data[:other_section] = "This should not be included in the response"
|
704
|
+
end
|
705
|
+
|
706
|
+
expected_data = {
|
707
|
+
error_class: :"Test Exception",
|
708
|
+
error_message: "Some Exception",
|
709
|
+
controller: "some_controller",
|
710
|
+
exception: @exception,
|
711
|
+
context: {
|
712
|
+
timestamp: Time.now.to_i,
|
713
|
+
error_class: "StandardError",
|
714
|
+
server: "invoca_fe98",
|
715
|
+
exception_context: { "SERVER_NAME" => "exceptional.com" },
|
716
|
+
scm_revision: "5b24eac37aaa91f5784901e9aabcead36fd9df82",
|
717
|
+
notes: "this is used by a test",
|
718
|
+
user_details: { "username" => "jsmith" },
|
719
|
+
request: {
|
720
|
+
"params" => { "advertiser_id" => 435, "controller" => "some_controller" },
|
721
|
+
"rails_root" => "Rails.root not defined. Is this a test environment?",
|
722
|
+
"url" => "host/path"
|
723
|
+
},
|
724
|
+
session: {
|
725
|
+
"key" => nil,
|
726
|
+
"data" => { "username" => "jsmith" }
|
727
|
+
},
|
728
|
+
environment: {
|
729
|
+
"SERVER_NAME" => "exceptional.com"
|
730
|
+
},
|
731
|
+
backtrace: [
|
732
|
+
"test/unit/exception_handling_test.rb:847:in `exception_1'",
|
733
|
+
"test/unit/exception_handling_test.rb:455:in `block (4 levels) in <class:ExceptionHandlingTest>'"
|
734
|
+
],
|
735
|
+
event_response: "Event successfully received"
|
736
|
+
}
|
676
737
|
}
|
677
|
-
|
678
|
-
|
738
|
+
assert_equal_with_diff expected_data, honeybadger_data
|
739
|
+
end
|
679
740
|
end
|
680
741
|
|
681
742
|
context "with post_log_error_hook set" 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.
|
4
|
+
version: 2.5.0.pre.2
|
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-19 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
|
@@ -150,6 +150,7 @@ files:
|
|
150
150
|
- lib/exception_handling/version.rb
|
151
151
|
- test/helpers/controller_helpers.rb
|
152
152
|
- test/helpers/exception_helpers.rb
|
153
|
+
- test/rake_test_warning_false.rb
|
153
154
|
- test/test_helper.rb
|
154
155
|
- test/unit/exception_handling/exception_catalog_test.rb
|
155
156
|
- test/unit/exception_handling/exception_description_test.rb
|
@@ -191,6 +192,7 @@ summary: Invoca's exception handling logger/emailer layer, based on exception_no
|
|
191
192
|
test_files:
|
192
193
|
- test/helpers/controller_helpers.rb
|
193
194
|
- test/helpers/exception_helpers.rb
|
195
|
+
- test/rake_test_warning_false.rb
|
194
196
|
- test/test_helper.rb
|
195
197
|
- test/unit/exception_handling/exception_catalog_test.rb
|
196
198
|
- test/unit/exception_handling/exception_description_test.rb
|