escalate 0.1.0.pre.1 → 0.1.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/Gemfile +2 -0
- data/Gemfile.lock +2 -2
- data/README.md +6 -2
- data/escalate.gemspec +2 -3
- data/lib/escalate.rb +29 -18
- data/lib/escalate/mixin.rb +2 -2
- data/lib/escalate/version.rb +1 -1
- metadata +4 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a3e33eb654953f4c511b2207a89df47f6db4865c
|
4
|
+
data.tar.gz: 4b245b1e402c24a933eae6ba6ac6eb9be362e5f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 28a1ecb9c22129c0b68c62ac6c5bd00eb5b41580bae1763dfdc9e0d9e732dfd22b7acc37ec84f353d4a3f7f35c18334ae92a78a5677c5e9e6453c4ccfb074767
|
7
|
+
data.tar.gz: dc2271ab38903b2c8f874adc0b21f26c3851a759f5ed1db34482d447573d3d8f13d8b8d1b5565b9106b73bde766dee65260aeb6c645d402b9326371536d3dce0
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
escalate (0.1.0.pre.
|
4
|
+
escalate (0.1.0.pre.2)
|
5
5
|
activesupport
|
6
|
-
contextual_logger
|
7
6
|
|
8
7
|
GEM
|
9
8
|
remote: https://rubygems.org/
|
@@ -53,6 +52,7 @@ PLATFORMS
|
|
53
52
|
x86_64-darwin-19
|
54
53
|
|
55
54
|
DEPENDENCIES
|
55
|
+
contextual_logger
|
56
56
|
escalate!
|
57
57
|
pry
|
58
58
|
pry-byebug
|
data/README.md
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
# Escalate
|
2
2
|
|
3
|
-
A simple and lightweight gem to
|
3
|
+
A simple and lightweight gem to escalate rescued exceptions. This implementation
|
4
|
+
is an abstract interface that can be used on it's own, or attached to more concrete
|
5
|
+
implementations like Honeybadger, Airbrake, or Sentry in order to not just log
|
6
|
+
exceptions in an easy to parse way, but also escalate the appropriate information
|
7
|
+
to third party systems.
|
4
8
|
|
5
9
|
## Installation
|
6
10
|
|
@@ -30,7 +34,7 @@ module SomeGem
|
|
30
34
|
end
|
31
35
|
```
|
32
36
|
|
33
|
-
This will expose the `Escalate#
|
37
|
+
This will expose the `Escalate#escalate` method within your gem to be used instead
|
34
38
|
of using `logger.error`.
|
35
39
|
|
36
40
|
```ruby
|
data/escalate.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.authors = ["Invoca Development", "Octothorp"]
|
9
9
|
spec.email = ["development@invoca.com", "octothorp@invoca.com"]
|
10
10
|
|
11
|
-
spec.summary = "
|
12
|
-
spec.description = "
|
11
|
+
spec.summary = "A simple and lightweight gem to escalate rescued exceptions."
|
12
|
+
spec.description = "A simple and lightweight gem to escalate rescued exceptions."
|
13
13
|
spec.homepage = "https://github.com/invoca/escalate"
|
14
14
|
spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
|
15
15
|
|
@@ -28,5 +28,4 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.require_paths = ["lib"]
|
29
29
|
|
30
30
|
spec.add_dependency "activesupport"
|
31
|
-
spec.add_dependency "contextual_logger"
|
32
31
|
end
|
data/lib/escalate.rb
CHANGED
@@ -2,7 +2,6 @@
|
|
2
2
|
|
3
3
|
require "active_support"
|
4
4
|
require "active_support/core_ext"
|
5
|
-
require "contextual_logger"
|
6
5
|
|
7
6
|
require_relative "escalate/version"
|
8
7
|
require_relative "escalate/mixin"
|
@@ -25,28 +24,29 @@ module Escalate
|
|
25
24
|
# @param [Hash] context
|
26
25
|
# Any additional context to be tied to the escalation
|
27
26
|
def escalate(exception, message, logger, **context)
|
28
|
-
|
29
|
-
|
30
|
-
#{
|
31
|
-
|
32
|
-
|
27
|
+
ensure_failsafe("Exception rescued while escalating #{exception.inspect}") do
|
28
|
+
error_message = <<~EOS
|
29
|
+
[Escalate] #{message} (#{context.inspect})
|
30
|
+
#{exception.class.name}: #{exception.message}
|
31
|
+
#{exception.backtrace.join("\n")}
|
32
|
+
EOS
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
34
|
+
if logger_allows_added_context?(logger)
|
35
|
+
logger.error(error_message, **context)
|
36
|
+
else
|
37
|
+
logger.error(error_message)
|
38
|
+
end
|
39
39
|
|
40
|
-
|
41
|
-
|
40
|
+
on_escalate_blocks.each do |block|
|
41
|
+
ensure_failsafe("Exception rescued while escalating #{exception.inspect} to #{block.inspect}") do
|
42
|
+
block.call(exception, message, **context)
|
43
|
+
end
|
44
|
+
end
|
42
45
|
end
|
43
|
-
rescue Exception => ex
|
44
|
-
STDERR.puts("[ExEscalator] Exception rescued while escalating #{exception.inspect}:" \
|
45
|
-
"#{ex.class.name}: #{ex.message}")
|
46
46
|
end
|
47
47
|
|
48
48
|
# Returns a module to be mixed into a class or module exposing
|
49
|
-
# the
|
49
|
+
# the escalate method to be used for escalating and logging
|
50
50
|
# exceptions.
|
51
51
|
#
|
52
52
|
# @param [Proc] logger_block
|
@@ -63,7 +63,7 @@ module Escalate
|
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
|
-
# Registers an escalation callback to be executed when `
|
66
|
+
# Registers an escalation callback to be executed when `escalate`
|
67
67
|
# is invoked.
|
68
68
|
def on_escalate(&block)
|
69
69
|
on_escalate_blocks.add(block)
|
@@ -71,6 +71,17 @@ module Escalate
|
|
71
71
|
|
72
72
|
private
|
73
73
|
|
74
|
+
def ensure_failsafe(message)
|
75
|
+
yield
|
76
|
+
rescue Exception => ex
|
77
|
+
STDERR.puts("[Escalator] #{message}: #{ex.class.name}: #{ex.message}")
|
78
|
+
end
|
79
|
+
|
80
|
+
def logger_allows_added_context?(logger)
|
81
|
+
defined?(ContextualLogger::LoggerMixin) &&
|
82
|
+
logger.is_a?(ContextualLogger::LoggerMixin)
|
83
|
+
end
|
84
|
+
|
74
85
|
def on_escalate_blocks
|
75
86
|
@on_escalate_blocks ||= Set.new
|
76
87
|
end
|
data/lib/escalate/mixin.rb
CHANGED
@@ -4,13 +4,13 @@ module Escalate
|
|
4
4
|
module Mixin
|
5
5
|
class << self
|
6
6
|
def included(base)
|
7
|
-
raise 'instead of `include
|
7
|
+
raise 'instead of `include Escalator::Mixin`, you should `include Escalator.mixin`'
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
11
|
attr_accessor :escalate_logger_block
|
12
12
|
|
13
|
-
def
|
13
|
+
def escalate(exception, message, **context)
|
14
14
|
Escalate.escalate(exception, message, escalate_logger, **context)
|
15
15
|
end
|
16
16
|
|
data/lib/escalate/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: escalate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.0.pre.
|
4
|
+
version: 0.1.0.pre.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Invoca Development
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2021-02-
|
12
|
+
date: 2021-02-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -25,21 +25,7 @@ dependencies:
|
|
25
25
|
- - ">="
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: '0'
|
28
|
-
|
29
|
-
name: contextual_logger
|
30
|
-
requirement: !ruby/object:Gem::Requirement
|
31
|
-
requirements:
|
32
|
-
- - ">="
|
33
|
-
- !ruby/object:Gem::Version
|
34
|
-
version: '0'
|
35
|
-
type: :runtime
|
36
|
-
prerelease: false
|
37
|
-
version_requirements: !ruby/object:Gem::Requirement
|
38
|
-
requirements:
|
39
|
-
- - ">="
|
40
|
-
- !ruby/object:Gem::Version
|
41
|
-
version: '0'
|
42
|
-
description: Simple gem for abstracting log escalations
|
28
|
+
description: A simple and lightweight gem to escalate rescued exceptions.
|
43
29
|
email:
|
44
30
|
- development@invoca.com
|
45
31
|
- octothorp@invoca.com
|
@@ -89,5 +75,5 @@ rubyforge_project:
|
|
89
75
|
rubygems_version: 2.6.13
|
90
76
|
signing_key:
|
91
77
|
specification_version: 4
|
92
|
-
summary:
|
78
|
+
summary: A simple and lightweight gem to escalate rescued exceptions.
|
93
79
|
test_files: []
|