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 +5 -5
- data/CHANGELOG.md +7 -0
- data/Gemfile.lock +2 -1
- data/lib/escalate.rb +39 -17
- data/lib/escalate/version.rb +1 -1
- metadata +8 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2a0dc76f8fb9f09d141c117b3b746b143078712c8d14687e9a413f9e0db0eee4
|
4
|
+
data.tar.gz: 0a8861399988e40db304ff5bed43a5a3c6359eb2f0853f162515c5883e74c613
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
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
|
16
|
+
# The exception that was rescued and needs to be escalated
|
17
17
|
#
|
18
|
-
# @param [String]
|
19
|
-
# An additional message
|
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,
|
26
|
+
def escalate(exception, location_message, logger, **context)
|
27
27
|
ensure_failsafe("Exception rescued while escalating #{exception.inspect}") do
|
28
|
-
|
29
|
-
|
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
|
-
|
33
|
+
EOS
|
33
34
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
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
|
-
|
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,
|
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,
|
67
|
-
Escalate.escalate(exception,
|
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
|
-
|
85
|
-
|
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
|
data/lib/escalate/version.rb
CHANGED
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.
|
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-
|
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:
|
72
|
+
version: 1.3.1
|
73
73
|
requirements: []
|
74
|
-
|
75
|
-
|
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: []
|