exception_handling 2.5.0 → 2.5.1.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: 7b8df9043df9ecc580c8ea91495410cf37316c113acf43ac7f28dfeb885e235d
4
- data.tar.gz: 84f2a6eac09d7388f3c9ffd2e58a4211231aff7ccfe8869b1e307c51e9b02788
3
+ metadata.gz: 5c3561b45435bb79e5ee48f090362ea006a0d522ab5b61809af57a56951d5aff
4
+ data.tar.gz: b711a085d3a0049dd5dfbf6e454cb4e948f5f20b2a5d561d6b05a40f0d5c33d8
5
5
  SHA512:
6
- metadata.gz: 958f9994d47ff6ab87082ed04411c62af377e5e317c8f8669c349d4d7d38f4c7d0a88f6119a2c2a83882ed1be8624baf6e4c67e5fe0bedaeeebcfea7921558e5
7
- data.tar.gz: c412244a874549ce99d8e0645ceb6b56a59b9b8b92ddba6cbfab8eb83e5159954d13e5e96e119519e4c9e97e5786412f9f3d60ebef66f4bd5aa5c71dbd70901c
6
+ metadata.gz: a98fa1af28748a12facbe69b35d56641204db4f43d700970115a476b6689f591e9cc9cd5301a6d8709751f386642f51dd07657efb27f85de1e6ad61173a0e08d
7
+ data.tar.gz: 143f2f54b21e73299b2486ddff7532e4142fa01e5e92544f1cf4c07d8fd2f5d6de53cacace2089816ae81ccad850e820569e8a60efebb3196e7524e3dd8f26bd
@@ -4,6 +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.5.1] - Unreleased
8
+ ### Changed
9
+ - Calling `log_warning` will now log with Severity::WARNING rather than FATAL.
10
+
7
11
  ## [2.5.0] - 2020-08-19
8
12
  ### Added
9
13
  - The `**log_context` passed to `log_error`/`log_warning`/`log_info` is now
@@ -37,6 +41,7 @@ Note: this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0
37
41
  ### Changed
38
42
  - No longer depends on hobo_support. Uses invoca-utils 0.3 instead.
39
43
 
44
+ [2.5.1]: https://github.com/Invoca/exception_handling/compare/v2.5.0...v2.5.1
40
45
  [2.5.0]: https://github.com/Invoca/exception_handling/compare/v2.4.4...v2.5.0
41
46
  [2.4.4]: https://github.com/Invoca/exception_handling/compare/v2.4.3...v2.4.4
42
47
  [2.4.3]: https://github.com/Invoca/exception_handling/compare/v2.4.2...v2.4.3
@@ -8,7 +8,7 @@ GIT
8
8
  PATH
9
9
  remote: .
10
10
  specs:
11
- exception_handling (2.5.0)
11
+ exception_handling (2.5.1.pre.1)
12
12
  actionmailer (>= 4.2, < 7.0)
13
13
  actionpack (>= 4.2, < 7.0)
14
14
  activesupport (>= 4.2, < 7.0)
@@ -222,7 +222,13 @@ module ExceptionHandling # never included
222
222
  #
223
223
  def write_exception_to_log(ex, exception_context, timestamp, log_context = {})
224
224
  ActiveSupport::Deprecation.silence do
225
- 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)
225
+ log_message = "#{exception_context}\n#{ex.class}: (#{encode_utf8(ex.message.to_s)}):\n " + clean_backtrace(ex).join("\n ") + "\n\n"
226
+
227
+ if ex.is_a?(Warning)
228
+ ExceptionHandling.logger.warn("\nExceptionHandlingWarning (Warning:#{timestamp}) #{log_message}", log_context)
229
+ else
230
+ ExceptionHandling.logger.fatal("\nExceptionHandlingError (Error:#{timestamp}) #{log_message}", log_context)
231
+ end
226
232
  end
227
233
  end
228
234
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ExceptionHandling
4
- VERSION = '2.5.0'
4
+ VERSION = '2.5.1.pre.1'
5
5
  end
@@ -33,16 +33,20 @@ class LoggerStub
33
33
  clear
34
34
  end
35
35
 
36
+ def debug(message, log_context = {})
37
+ logged << { message: message, context: log_context, severity: 'DEBUG' }
38
+ end
39
+
36
40
  def info(message, log_context = {})
37
- logged << { message: message, context: log_context }
41
+ logged << { message: message, context: log_context, severity: 'INFO' }
38
42
  end
39
43
 
40
44
  def warn(message, log_context = {})
41
- logged << { message: message, context: log_context }
45
+ logged << { message: message, context: log_context, severity: 'WARN' }
42
46
  end
43
47
 
44
48
  def fatal(message, log_context = {})
45
- logged << { message: message, context: log_context }
49
+ logged << { message: message, context: log_context, severity: 'FATAL' }
46
50
  end
47
51
 
48
52
  def clear
@@ -149,6 +149,11 @@ class ExceptionHandlingTest < ActiveSupport::TestCase
149
149
  assert_not_empty logged_excluding_reload_filter.last[:context]
150
150
  assert_equal logged_excluding_reload_filter.last[:context], service_name: 'exception_handling'
151
151
  end
152
+
153
+ should "log with Severity::FATAL" do
154
+ ExceptionHandling.log_error('This is a Warning', service_name: 'exception_handling')
155
+ assert_equal logged_excluding_reload_filter.last[:severity], 'FATAL'
156
+ end
152
157
  end
153
158
 
154
159
  context "#log_warning" do
@@ -165,24 +170,53 @@ class ExceptionHandlingTest < ActiveSupport::TestCase
165
170
  assert_not_empty logged_excluding_reload_filter.last[:context]
166
171
  assert_equal logged_excluding_reload_filter.last[:context], service_name: 'exception_handling'
167
172
  end
173
+
174
+ should "log with Severity::WARN" do
175
+ ExceptionHandling.log_warning('This is a Warning', service_name: 'exception_handling')
176
+ assert_equal logged_excluding_reload_filter.last[:severity], 'WARN'
177
+ end
168
178
  end
169
179
 
170
180
  context "#log_info" do
171
181
  should "take in additional key word args as logging context and pass them to the logger" do
172
- ExceptionHandling.log_warning('This is an Info', service_name: 'exception_handling')
182
+ ExceptionHandling.log_info('This is an Info', service_name: 'exception_handling')
173
183
  assert_match(/This is an Info/, logged_excluding_reload_filter.last[:message])
174
184
  assert_not_empty logged_excluding_reload_filter.last[:context]
175
185
  assert_equal logged_excluding_reload_filter.last[:context], service_name: 'exception_handling'
176
186
  end
187
+
188
+ should "log with Severity::INFO" do
189
+ ExceptionHandling.log_info('This is a Warning', service_name: 'exception_handling')
190
+ assert_equal logged_excluding_reload_filter.last[:severity], 'INFO'
191
+ end
177
192
  end
178
193
 
179
194
  context "#log_debug" do
180
195
  should "take in additional key word args as logging context and pass them to the logger" do
181
- ExceptionHandling.log_warning('This is a Debug', service_name: 'exception_handling')
196
+ ExceptionHandling.log_debug('This is a Debug', service_name: 'exception_handling')
182
197
  assert_match(/This is a Debug/, logged_excluding_reload_filter.last[:message])
183
198
  assert_not_empty logged_excluding_reload_filter.last[:context]
184
199
  assert_equal logged_excluding_reload_filter.last[:context], service_name: 'exception_handling'
185
200
  end
201
+
202
+ should "log with Severity::DEBUG" do
203
+ ExceptionHandling.log_debug('This is a Warning', service_name: 'exception_handling')
204
+ assert_equal logged_excluding_reload_filter.last[:severity], 'DEBUG'
205
+ end
206
+ end
207
+
208
+ context "#write_exception_to_log" do
209
+ should "log warnings with Severity::WARN" do
210
+ warning = ExceptionHandling::Warning.new('This is a Warning')
211
+ ExceptionHandling.write_exception_to_log(warning, '', Time.now.to_i, service_name: 'exception_handling')
212
+ assert_equal logged_excluding_reload_filter.last[:severity], 'WARN'
213
+ end
214
+
215
+ should "log everything else with Severity::FATAL" do
216
+ error = RuntimeError.new('This is a runtime error')
217
+ ExceptionHandling.write_exception_to_log(error, '', Time.now.to_i, service_name: 'exception_handling')
218
+ assert_equal logged_excluding_reload_filter.last[:severity], 'FATAL'
219
+ end
186
220
  end
187
221
 
188
222
  context "configuration with custom_data_hook or post_log_error_hook" do
@@ -339,7 +373,7 @@ class ExceptionHandlingTest < ActiveSupport::TestCase
339
373
 
340
374
  if ActionView::VERSION::MAJOR >= 5
341
375
  should "log an exception with call stack if an ActionView template exception is raised." do
342
- mock(ExceptionHandling.logger).fatal(/\(Error:\d+\) ActionView::Template::Error \(blah\):\n /, anything)
376
+ mock(ExceptionHandling.logger).fatal(/\(Error:\d+\) \nActionView::Template::Error: \(blah\):\n /, anything)
343
377
  ExceptionHandling.ensure_safe do
344
378
  begin
345
379
  # Rails 5 made the switch from ActionView::TemplateError taking in the original exception
@@ -352,7 +386,7 @@ class ExceptionHandlingTest < ActiveSupport::TestCase
352
386
  end
353
387
  else
354
388
  should "log an exception with call stack if an ActionView template exception is raised." do
355
- mock(ExceptionHandling.logger).fatal(/\(Error:\d+\) ActionView::Template::Error \(blah\):\n /, anything)
389
+ mock(ExceptionHandling.logger).fatal(/\(Error:\d+\) \nActionView::Template::Error: \(blah\):\n /, anything)
356
390
  ExceptionHandling.ensure_safe { raise ActionView::TemplateError.new({}, ArgumentError.new("blah")) }
357
391
  end
358
392
  end
@@ -375,7 +409,7 @@ class ExceptionHandlingTest < ActiveSupport::TestCase
375
409
  end
376
410
 
377
411
  should "allow a message to be appended to the error when logged." do
378
- mock(ExceptionHandling.logger).fatal(/mooo \(blah\):\n.*exception_handling_test\.rb/, anything)
412
+ mock(ExceptionHandling.logger).fatal(/mooo\nArgumentError: \(blah\):\n.*exception_handling_test\.rb/, anything)
379
413
  b = ExceptionHandling.ensure_safe("mooo") { raise ArgumentError, "blah" }
380
414
  assert_nil b
381
415
  end
@@ -383,7 +417,7 @@ class ExceptionHandlingTest < ActiveSupport::TestCase
383
417
  should "only rescue StandardError and descendents" do
384
418
  assert_raise(Exception) { ExceptionHandling.ensure_safe("mooo") { raise Exception } }
385
419
 
386
- mock(ExceptionHandling.logger).fatal(/mooo \(blah\):\n.*exception_handling_test\.rb/, anything)
420
+ mock(ExceptionHandling.logger).fatal(/mooo\nStandardError: \(blah\):\n.*exception_handling_test\.rb/, anything)
387
421
 
388
422
  b = ExceptionHandling.ensure_safe("mooo") { raise StandardError, "blah" }
389
423
  assert_nil b
@@ -414,7 +448,7 @@ class ExceptionHandlingTest < ActiveSupport::TestCase
414
448
  end
415
449
 
416
450
  should "allow a message to be appended to the error when logged." do
417
- mock(ExceptionHandling.logger).fatal(/mooo \(blah\):\n.*exception_handling_test\.rb/, anything)
451
+ mock(ExceptionHandling.logger).fatal(/mooo\nArgumentError: \(blah\):\n.*exception_handling_test\.rb/, anything)
418
452
  b = ExceptionHandling.ensure_completely_safe("mooo") { raise ArgumentError, "blah" }
419
453
  assert_nil b
420
454
  end
@@ -471,7 +505,7 @@ class ExceptionHandlingTest < ActiveSupport::TestCase
471
505
  ExceptionHandling.ensure_escalation("ensure context") { raise ArgumentError, "first_test_exception" }
472
506
 
473
507
  assert_match(/ArgumentError.*first_test_exception/, log_fatals[0].first)
474
- assert_match(/safe_email_deliver.*Delivery Error/, log_fatals[1].first)
508
+ assert_match(/safe_email_deliver.*Delivery Error/m, log_fatals[1].first)
475
509
 
476
510
  assert_equal 2, log_fatals.size, log_fatals.inspect
477
511
 
@@ -541,7 +575,7 @@ class ExceptionHandlingTest < ActiveSupport::TestCase
541
575
  should "include the timestamp when the exception is logged" do
542
576
  capture_notifications
543
577
 
544
- mock(ExceptionHandling.logger).fatal(/\(Error:517033020\) ArgumentError context \(blah\):\n.*exception_handling_test\.rb/, anything)
578
+ mock(ExceptionHandling.logger).fatal(/\(Error:517033020\) context\nArgumentError: \(blah\):\n.*exception_handling_test\.rb/, anything)
545
579
  b = ExceptionHandling.ensure_safe("context") { raise ArgumentError, "blah" }
546
580
  assert_nil b
547
581
 
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.5.0
4
+ version: 2.5.1.pre.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Invoca
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-20 00:00:00.000000000 Z
11
+ date: 2020-08-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionmailer
@@ -169,7 +169,7 @@ licenses: []
169
169
  metadata:
170
170
  source_code_uri: https://github.com/Invoca/exception_handling
171
171
  allowed_push_host: https://rubygems.org
172
- post_install_message:
172
+ post_install_message:
173
173
  rdoc_options: []
174
174
  require_paths:
175
175
  - lib
@@ -180,12 +180,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
180
180
  version: '0'
181
181
  required_rubygems_version: !ruby/object:Gem::Requirement
182
182
  requirements:
183
- - - ">="
183
+ - - ">"
184
184
  - !ruby/object:Gem::Version
185
- version: '0'
185
+ version: 1.3.1
186
186
  requirements: []
187
187
  rubygems_version: 3.0.3
188
- signing_key:
188
+ signing_key:
189
189
  specification_version: 4
190
190
  summary: Invoca's exception handling logger/emailer layer, based on exception_notifier.
191
191
  Works with Rails or EventMachine or EventMachine+Synchrony.