escalate 0.1.0 → 0.2.0.pre.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: ca403c35fe8123ebf15d068d392789e5de418f71
4
- data.tar.gz: df6eb4d755258ce4e6d3617ca88075266e591acc
2
+ SHA256:
3
+ metadata.gz: 2a0dc76f8fb9f09d141c117b3b746b143078712c8d14687e9a413f9e0db0eee4
4
+ data.tar.gz: 0a8861399988e40db304ff5bed43a5a3c6359eb2f0853f162515c5883e74c613
5
5
  SHA512:
6
- metadata.gz: aae531b8f6fc1f8bb4e52a2cbf1ff613fd74f19298ca18aca77936f6e44b741c9ce42b02817bcfb755379d95c6e577342b1a17af0a387e66a00348baf96a3703
7
- data.tar.gz: 2d4c26aad91e60c1c2b192b66d6f332db6a858b7f06588788f5b166d41912a8daa27cac39d166ac3cea7e770417037062add542bf36f4429a8c0cc8f0ad74a7b
6
+ metadata.gz: 95f0fd83333e4245756cee9c5fff725255a8b81e954102ad22e8d0d2c0f49bf27050c15154a00a309d4c0bce8f9edd7e5247aba3dfdc8b2f9b1fa64cbf281ab8
7
+ data.tar.gz: 62f87cc4801ff0a5187c251ec2fe0e47433d52ab4bdc89558af29a57f6bbf50ee912c9e92127c4a152a5008cf1d7e3110735b8082ec540b6aac9e7d95bf2fa18
data/CHANGELOG.md CHANGED
@@ -4,10 +4,17 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [0.2.0] - Unreleased
8
+ ### Added
9
+ - Added support for `on_escalate(log_first: false)`. The `escalate` gem will log first before
10
+ escalating if either of these is true: there are no `on_escalate` blocks registered, or
11
+ there are some and at least one of them passed `log_first: false`.
12
+
7
13
  ## [0.1.0] - 2021-02-03
8
14
  ### Added
9
15
  - Added `Escalate.mixin` interface for mixing in `Escalate` with your module for easy escalation of rescued exceptions
10
16
  - Added `escalate` method for escalating rescued exceptions with default behavior of logging to `STDERR`
11
17
  - Added `Escalate.on_escalate` for registering escalation callbacks like `Honeybadger` or `Sentry`
12
18
 
19
+ [0.2.0]: https://github.com/Invoca/escalate/compare/v0.1.0...v0.2.0
13
20
  [0.1.0]: https://github.com/Invoca/escalate/releases/tag/v0.1.0
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- escalate (0.1.0)
4
+ escalate (0.2.0.pre.1)
5
5
  activesupport
6
6
 
7
7
  GEM
@@ -49,6 +49,7 @@ GEM
49
49
  thread_safe (~> 0.1)
50
50
 
51
51
  PLATFORMS
52
+ ruby
52
53
  x86_64-darwin-19
53
54
 
54
55
  DEPENDENCIES
data/lib/escalate.rb CHANGED
@@ -13,33 +13,35 @@ module Escalate
13
13
  # Logs and escalated an exception
14
14
  #
15
15
  # @param [Exception] exception
16
- # The exception that was raised and needs to be escalated
16
+ # The exception that was rescued and needs to be escalated
17
17
  #
18
- # @param [String] message
19
- # An additional message about what was happening at the time of the exception
18
+ # @param [String] location_message
19
+ # An additional message giving an indication of where in the code this exception was rescued
20
20
  #
21
21
  # @param [Logger] logger
22
22
  # The logger object to use when logging the exception
23
23
  #
24
24
  # @param [Hash] context
25
25
  # Any additional context to be tied to the escalation
26
- def escalate(exception, message, logger, **context)
26
+ def escalate(exception, location_message, logger, **context)
27
27
  ensure_failsafe("Exception rescued while escalating #{exception.inspect}") do
28
- error_message = <<~EOS
29
- [Escalate] #{message} (#{context.inspect})
28
+ if on_escalate_blocks.any? || on_escalate_no_log_first_blocks.none?
29
+ error_message = <<~EOS
30
+ [Escalate] #{location_message} (#{context.inspect})
30
31
  #{exception.class.name}: #{exception.message}
31
32
  #{exception.backtrace.join("\n")}
32
- EOS
33
+ EOS
33
34
 
34
- if logger_allows_added_context?(logger)
35
- logger.error(error_message, **context)
36
- else
37
- logger.error(error_message)
35
+ if logger_allows_added_context?(logger)
36
+ logger.error(error_message, **context)
37
+ else
38
+ logger.error(error_message)
39
+ end
38
40
  end
39
41
 
40
- on_escalate_blocks.each do |block|
42
+ all_on_escalate_blocks.each do |block|
41
43
  ensure_failsafe("Exception rescued while escalating #{exception.inspect} to #{block.inspect}") do
42
- block.call(exception, message, **context)
44
+ block.call(exception, location_message, **context)
43
45
  end
44
46
  end
45
47
  end
@@ -63,8 +65,8 @@ module Escalate
63
65
 
64
66
  attr_accessor :escalate_logger_block
65
67
 
66
- def escalate(exception, message, **context)
67
- Escalate.escalate(exception, message, escalate_logger, **context)
68
+ def escalate(exception, location_message, **context)
69
+ Escalate.escalate(exception, location_message, escalate_logger, **context)
68
70
  end
69
71
 
70
72
  private
@@ -81,8 +83,20 @@ module Escalate
81
83
 
82
84
  # Registers an escalation callback to be executed when `escalate`
83
85
  # is invoked.
84
- def on_escalate(&block)
85
- on_escalate_blocks.add(block)
86
+ #
87
+ # @param [boolean] log_first: true
88
+ # whether escalate should log first before escalating, or leave the logging to the escalate block
89
+ def on_escalate(log_first: true, &block)
90
+ if log_first
91
+ on_escalate_blocks.add(block)
92
+ else
93
+ on_escalate_no_log_first_blocks.add(block)
94
+ end
95
+ end
96
+
97
+ def clear_all_on_escalate_blocks
98
+ on_escalate_blocks.clear
99
+ on_escalate_no_log_first_blocks.clear
86
100
  end
87
101
 
88
102
  private
@@ -101,5 +115,13 @@ module Escalate
101
115
  def on_escalate_blocks
102
116
  @on_escalate_blocks ||= Set.new
103
117
  end
118
+
119
+ def on_escalate_no_log_first_blocks
120
+ @on_escalate_no_log_first_blocks ||= Set.new
121
+ end
122
+
123
+ def all_on_escalate_blocks
124
+ on_escalate_blocks + on_escalate_no_log_first_blocks
125
+ end
104
126
  end
105
127
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Escalate
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0.pre.1"
5
5
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: escalate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0.pre.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Invoca Development
8
8
  - Octothorp
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-02-03 00:00:00.000000000 Z
12
+ date: 2021-02-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -56,7 +56,7 @@ metadata:
56
56
  allowed_push_host: https://rubygems.org
57
57
  homepage_uri: https://github.com/invoca/escalate
58
58
  changelog_uri: https://github.com/invoca/escalate/blob/main/CHANGELOG.md
59
- post_install_message:
59
+ post_install_message:
60
60
  rdoc_options: []
61
61
  require_paths:
62
62
  - lib
@@ -67,13 +67,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
67
67
  version: 2.4.0
68
68
  required_rubygems_version: !ruby/object:Gem::Requirement
69
69
  requirements:
70
- - - ">="
70
+ - - ">"
71
71
  - !ruby/object:Gem::Version
72
- version: '0'
72
+ version: 1.3.1
73
73
  requirements: []
74
- rubyforge_project:
75
- rubygems_version: 2.6.13
76
- signing_key:
74
+ rubygems_version: 3.1.2
75
+ signing_key:
77
76
  specification_version: 4
78
77
  summary: A simple and lightweight gem to escalate rescued exceptions.
79
78
  test_files: []