barsoom_utils 0.2.0.76 → 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: bc8c7ab6a54929794df46c90b1cbe14474f0461989ee071a5917176c057db757
4
- data.tar.gz: d016e08c7b0b8fe901eaabafa14027bb9da1c533967b69e078b74191c7da9693
3
+ metadata.gz: f10ec24dca48ed3703590008317664ee7993d1efbfd0b3d4c5cc1d876c5712ca
4
+ data.tar.gz: c9d43fdc45e23e2a267c390007cc5c685273d5da581f8a413fb2da106ec25d08
5
5
  SHA512:
6
- metadata.gz: 0b126fb0cbb946764f8e2132e27fd8aaf546857a00caf378086ac20caeffaff5cad49a004472e89397c759e5e704d074a54fd61cf8df8277bce7b2694c511664
7
- data.tar.gz: f8d54ae7b4b409da656cc85af93cb47fc12aa436d8f59e90b39521323f9c76505cf5631713d5ac437fe1488b8c49bd2a576ed1a963d014db73234b21a6571e39
6
+ metadata.gz: bfb7e4a46b94501ce9d505c0b19b674006f75c48cd3b16f18c7573c6d006ab41f9b3196529a5fa6a383d7c2454a41ac12dcfacd3da05db9e40b19f217715ae32
7
+ data.tar.gz: f9e748ad9dfb716d217df3420fafb7ac93c859d07b240e24dcd9c668b9ff741f9d6631a6f467abea7ca24a71867e39ed8b37885a4ea53ab15e0ee83f3593b277
data/Gemfile CHANGED
@@ -15,4 +15,5 @@ group :development, :test do
15
15
  gem "redis"
16
16
  gem "rspec"
17
17
  gem "rubocop"
18
+ gem "sentry-ruby"
18
19
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0.76
1
+ 0.2.0.78
@@ -11,10 +11,16 @@ module BarsoomUtils
11
11
  raise "Expected an exception but got: #{exception.inspect}"
12
12
  end
13
13
 
14
- Honeybadger.notify(exception, context: context)
14
+ ensure_notifier!
15
+
16
+ result = Honeybadger.notify(exception, context: context) if defined?(Honeybadger)
17
+ Sentry.capture_exception(exception, extra: context) if defined?(Sentry)
18
+ result
15
19
  end
16
20
 
17
21
  def self.message(message, details_or_context = nil, context_or_nothing = nil)
22
+ ensure_notifier!
23
+
18
24
  if context_or_nothing
19
25
  details = details_or_context
20
26
  context = context_or_nothing
@@ -26,13 +32,29 @@ module BarsoomUtils
26
32
  context = {}
27
33
  end
28
34
 
29
- details ||= "(no message)"
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
42
+
43
+ if defined?(Sentry)
44
+ title = details ? "#{message}: #{details}" : message.to_s
45
+ Sentry.capture_message(title, extra: context.to_h)
46
+ end
47
+
48
+ result
49
+ end
50
+
51
+ private
52
+
53
+ private_class_method \
54
+ def self.ensure_notifier!
55
+ return if defined?(Honeybadger) || defined?(Sentry)
30
56
 
31
- Honeybadger.notify(
32
- error_class: message,
33
- error_message: details.to_s,
34
- context: context.to_h,
35
- )
57
+ raise "Cannot notify: neither Honeybadger nor Sentry is available."
36
58
  end
37
59
  end
38
60
  end
@@ -1,26 +1,31 @@
1
1
  # frozen_string_literal: true
2
2
  require "barsoom_utils/exception_notifier"
3
3
  require "honeybadger"
4
+ require "sentry-ruby"
4
5
  require "fixme"
5
6
 
6
7
  RSpec.describe BarsoomUtils::ExceptionNotifier do
7
8
  before do
8
9
  allow(Honeybadger).to receive(:notify)
10
+ allow(Sentry).to receive(:capture_exception)
11
+ allow(Sentry).to receive(:capture_message)
9
12
  end
10
13
 
11
14
  describe ".notify" do
12
15
  let(:ex) { StandardError.new("boom") }
13
16
 
14
- it "passes an exception to Honeybadger" do
17
+ it "passes an exception to Honeybadger and Sentry" do
15
18
  BarsoomUtils::ExceptionNotifier.notify(ex)
16
19
 
17
20
  expect(Honeybadger).to have_received(:notify).with(ex, context: {})
21
+ expect(Sentry).to have_received(:capture_exception).with(ex, extra: {})
18
22
  end
19
23
 
20
24
  it "can pass through context info" do
21
25
  BarsoomUtils::ExceptionNotifier.notify(ex, context: { foo: "bar" })
22
26
 
23
27
  expect(Honeybadger).to have_received(:notify).with(ex, context: { foo: "bar" })
28
+ expect(Sentry).to have_received(:capture_exception).with(ex, extra: { foo: "bar" })
24
29
  end
25
30
 
26
31
  it "complains if given a non-exception" do
@@ -29,11 +34,51 @@ RSpec.describe BarsoomUtils::ExceptionNotifier do
29
34
  }.to raise_error(/Expected an exception but got:.*foo.*bar/)
30
35
 
31
36
  expect(Honeybadger).not_to have_received(:notify)
37
+ expect(Sentry).not_to have_received(:capture_exception)
38
+ end
39
+
40
+ it "returns Honeybadger's result" do
41
+ allow(Honeybadger).to receive(:notify).and_return(:sentinel)
42
+
43
+ expect(BarsoomUtils::ExceptionNotifier.notify(ex)).to eq(:sentinel)
44
+ end
45
+
46
+ context "without Sentry" do
47
+ before { hide_const("Sentry") }
48
+
49
+ it "still notifies Honeybadger and raises nothing" do
50
+ BarsoomUtils::ExceptionNotifier.notify(ex, context: { foo: "bar" })
51
+
52
+ expect(Honeybadger).to have_received(:notify).with(ex, context: { foo: "bar" })
53
+ end
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
32
77
  end
33
78
  end
34
79
 
35
80
  describe ".message" do
36
- it "passes a message to Honeybadger" do
81
+ it "passes a message to Honeybadger and Sentry" do
37
82
  BarsoomUtils::ExceptionNotifier.message("Boom!")
38
83
 
39
84
  expect(Honeybadger).to have_received(:notify).with(
@@ -41,6 +86,7 @@ RSpec.describe BarsoomUtils::ExceptionNotifier do
41
86
  error_message: "(no message)",
42
87
  context: {},
43
88
  )
89
+ expect(Sentry).to have_received(:capture_message).with("Boom!", extra: {})
44
90
  end
45
91
 
46
92
  it "can take a custom details string" do
@@ -51,6 +97,13 @@ RSpec.describe BarsoomUtils::ExceptionNotifier do
51
97
  error_message: "Details!",
52
98
  context: {},
53
99
  )
100
+ expect(Sentry).to have_received(:capture_message).with("Boom!: Details!", extra: {})
101
+ end
102
+
103
+ it "coerces the message to a string for Sentry" do
104
+ BarsoomUtils::ExceptionNotifier.message(:boom)
105
+
106
+ expect(Sentry).to have_received(:capture_message).with("boom", extra: {})
54
107
  end
55
108
 
56
109
  it "can take a context hash" do
@@ -61,6 +114,7 @@ RSpec.describe BarsoomUtils::ExceptionNotifier do
61
114
  error_message: "(no message)",
62
115
  context: { foo: "bar" },
63
116
  )
117
+ expect(Sentry).to have_received(:capture_message).with("Boom!", extra: { foo: "bar" })
64
118
  end
65
119
 
66
120
  it "can take a custom details string and a context hash" do
@@ -71,6 +125,50 @@ RSpec.describe BarsoomUtils::ExceptionNotifier do
71
125
  error_message: "Details!",
72
126
  context: { foo: "bar" },
73
127
  )
128
+ expect(Sentry).to have_received(:capture_message).with("Boom!: Details!", extra: { foo: "bar" })
129
+ end
130
+
131
+ it "returns Honeybadger's result" do
132
+ allow(Honeybadger).to receive(:notify).and_return(:sentinel)
133
+
134
+ expect(BarsoomUtils::ExceptionNotifier.message("Boom!")).to eq(:sentinel)
135
+ end
136
+
137
+ context "without Sentry" do
138
+ before { hide_const("Sentry") }
139
+
140
+ it "still notifies Honeybadger and raises nothing" do
141
+ BarsoomUtils::ExceptionNotifier.message("Boom!", "Details!", foo: "bar")
142
+
143
+ expect(Honeybadger).to have_received(:notify).with(
144
+ error_class: "Boom!",
145
+ error_message: "Details!",
146
+ context: { foo: "bar" },
147
+ )
148
+ end
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
74
172
  end
75
173
  end
76
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.76
4
+ version: 0.2.0.78
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomas Skogberg