barsoom_utils 0.2.0.77 → 0.2.0.78
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/VERSION +1 -1
- data/lib/barsoom_utils/exception_notifier.rb +21 -6
- data/spec/exception_notifier_spec.rb +46 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f10ec24dca48ed3703590008317664ee7993d1efbfd0b3d4c5cc1d876c5712ca
|
|
4
|
+
data.tar.gz: c9d43fdc45e23e2a267c390007cc5c685273d5da581f8a413fb2da106ec25d08
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bfb7e4a46b94501ce9d505c0b19b674006f75c48cd3b16f18c7573c6d006ab41f9b3196529a5fa6a383d7c2454a41ac12dcfacd3da05db9e40b19f217715ae32
|
|
7
|
+
data.tar.gz: f9e748ad9dfb716d217df3420fafb7ac93c859d07b240e24dcd9c668b9ff741f9d6631a6f467abea7ca24a71867e39ed8b37885a4ea53ab15e0ee83f3593b277
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.2.0.
|
|
1
|
+
0.2.0.78
|
|
@@ -11,12 +11,16 @@ module BarsoomUtils
|
|
|
11
11
|
raise "Expected an exception but got: #{exception.inspect}"
|
|
12
12
|
end
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
ensure_notifier!
|
|
15
|
+
|
|
16
|
+
result = Honeybadger.notify(exception, context: context) if defined?(Honeybadger)
|
|
15
17
|
Sentry.capture_exception(exception, extra: context) if defined?(Sentry)
|
|
16
18
|
result
|
|
17
19
|
end
|
|
18
20
|
|
|
19
21
|
def self.message(message, details_or_context = nil, context_or_nothing = nil)
|
|
22
|
+
ensure_notifier!
|
|
23
|
+
|
|
20
24
|
if context_or_nothing
|
|
21
25
|
details = details_or_context
|
|
22
26
|
context = context_or_nothing
|
|
@@ -28,11 +32,13 @@ module BarsoomUtils
|
|
|
28
32
|
context = {}
|
|
29
33
|
end
|
|
30
34
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
35
|
+
if defined?(Honeybadger)
|
|
36
|
+
result = Honeybadger.notify(
|
|
37
|
+
error_class: message,
|
|
38
|
+
error_message: (details || "(no message)").to_s,
|
|
39
|
+
context: context.to_h,
|
|
40
|
+
)
|
|
41
|
+
end
|
|
36
42
|
|
|
37
43
|
if defined?(Sentry)
|
|
38
44
|
title = details ? "#{message}: #{details}" : message.to_s
|
|
@@ -41,5 +47,14 @@ module BarsoomUtils
|
|
|
41
47
|
|
|
42
48
|
result
|
|
43
49
|
end
|
|
50
|
+
|
|
51
|
+
private
|
|
52
|
+
|
|
53
|
+
private_class_method \
|
|
54
|
+
def self.ensure_notifier!
|
|
55
|
+
return if defined?(Honeybadger) || defined?(Sentry)
|
|
56
|
+
|
|
57
|
+
raise "Cannot notify: neither Honeybadger nor Sentry is available."
|
|
58
|
+
end
|
|
44
59
|
end
|
|
45
60
|
end
|
|
@@ -52,6 +52,29 @@ RSpec.describe BarsoomUtils::ExceptionNotifier do
|
|
|
52
52
|
expect(Honeybadger).to have_received(:notify).with(ex, context: { foo: "bar" })
|
|
53
53
|
end
|
|
54
54
|
end
|
|
55
|
+
|
|
56
|
+
context "without Honeybadger" do
|
|
57
|
+
before { hide_const("Honeybadger") }
|
|
58
|
+
|
|
59
|
+
it "still notifies Sentry and raises nothing" do
|
|
60
|
+
BarsoomUtils::ExceptionNotifier.notify(ex, context: { foo: "bar" })
|
|
61
|
+
|
|
62
|
+
expect(Sentry).to have_received(:capture_exception).with(ex, extra: { foo: "bar" })
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
context "without either notifier" do
|
|
67
|
+
before do
|
|
68
|
+
hide_const("Honeybadger")
|
|
69
|
+
hide_const("Sentry")
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
it "raises" do
|
|
73
|
+
expect {
|
|
74
|
+
BarsoomUtils::ExceptionNotifier.notify(ex)
|
|
75
|
+
}.to raise_error(/neither Honeybadger nor Sentry/)
|
|
76
|
+
end
|
|
77
|
+
end
|
|
55
78
|
end
|
|
56
79
|
|
|
57
80
|
describe ".message" do
|
|
@@ -124,5 +147,28 @@ RSpec.describe BarsoomUtils::ExceptionNotifier do
|
|
|
124
147
|
)
|
|
125
148
|
end
|
|
126
149
|
end
|
|
150
|
+
|
|
151
|
+
context "without Honeybadger" do
|
|
152
|
+
before { hide_const("Honeybadger") }
|
|
153
|
+
|
|
154
|
+
it "still notifies Sentry and raises nothing" do
|
|
155
|
+
BarsoomUtils::ExceptionNotifier.message("Boom!", "Details!", foo: "bar")
|
|
156
|
+
|
|
157
|
+
expect(Sentry).to have_received(:capture_message).with("Boom!: Details!", extra: { foo: "bar" })
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
context "without either notifier" do
|
|
162
|
+
before do
|
|
163
|
+
hide_const("Honeybadger")
|
|
164
|
+
hide_const("Sentry")
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
it "raises" do
|
|
168
|
+
expect {
|
|
169
|
+
BarsoomUtils::ExceptionNotifier.message("Boom!")
|
|
170
|
+
}.to raise_error(/neither Honeybadger nor Sentry/)
|
|
171
|
+
end
|
|
172
|
+
end
|
|
127
173
|
end
|
|
128
174
|
end
|