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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a689d68093a31c8481296dfbf97d19a683637dca75178cb142164b4ce11260a5
4
- data.tar.gz: 8477a0ab5a7700c7bf0897c7a239ec8b48d155f934b81ffaef0c93d75c42faf9
3
+ metadata.gz: f10ec24dca48ed3703590008317664ee7993d1efbfd0b3d4c5cc1d876c5712ca
4
+ data.tar.gz: c9d43fdc45e23e2a267c390007cc5c685273d5da581f8a413fb2da106ec25d08
5
5
  SHA512:
6
- metadata.gz: bb2a240db5388ccb1634a17fd3820aa3f6dbc161ec953be78ed03ceb111e1832b0d5350adec45bd81eb1ea6133d32507243811ab106e306c1342a6d3bdfea766
7
- data.tar.gz: 7f45fde4df510c8f92895eda05b97300dc6e3f272bb4f9220f50cb516b9748a2d1c89277f60bc1e2d24789354423bc8360d7e6992508f2831fa364943e7feb30
6
+ metadata.gz: bfb7e4a46b94501ce9d505c0b19b674006f75c48cd3b16f18c7573c6d006ab41f9b3196529a5fa6a383d7c2454a41ac12dcfacd3da05db9e40b19f217715ae32
7
+ data.tar.gz: f9e748ad9dfb716d217df3420fafb7ac93c859d07b240e24dcd9c668b9ff741f9d6631a6f467abea7ca24a71867e39ed8b37885a4ea53ab15e0ee83f3593b277
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0.77
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
- result = Honeybadger.notify(exception, context: context)
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
- result = Honeybadger.notify(
32
- error_class: message,
33
- error_message: (details || "(no message)").to_s,
34
- context: context.to_h,
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: barsoom_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0.77
4
+ version: 0.2.0.78
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomas Skogberg