Skip to content

Commit bdfa233

Browse files
authored
Directly execute ActionCable's action if the SDK is not initialized (#1692)
* Directly execute the block if the SDK is not initialized * Update changelog
1 parent ca9dadf commit bdfa233

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
### Bug Fixes
2+
3+
- Directly execute ActionCable's action if the SDK is not initialized [#1692](https://github.com/getsentry/sentry-ruby/pull/1692)
4+
- Fixes [#1691](https://github.com/getsentry/sentry-ruby/issues/1691)
5+
16
## 4.9.1
27

38
### Bug Fixes

sentry-rails/lib/sentry/rails/action_cable.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module ActionCableExtensions
44
class ErrorHandler
55
class << self
66
def capture(connection, transaction_name:, extra_context: nil, &block)
7+
return block.call unless Sentry.initialized?
78
# ActionCable's ConnectionStub (for testing) doesn't implement the exact same interfaces as Connection::Base.
89
# One thing that's missing is `env`. So calling `connection.env` direclty will fail in test environments when `stub_connection` is used.
910
# See https://github.com/getsentry/sentry-ruby/pull/1684 for more information.

sentry-rails/spec/sentry/rails/action_cable_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,19 @@ def disconnect
3232
end
3333
end
3434

35+
RSpec.describe "without Sentry initialized" do
36+
before do
37+
allow(Sentry).to receive(:get_main_hub).and_return(nil)
38+
make_basic_app
39+
Sentry.clone_hub_to_current_thread # make sure the thread doesn't set a hub
40+
end
41+
42+
describe ChatChannel, type: :channel do
43+
it "doesn't swallow the app's operation" do
44+
expect { subscribe }.to raise_error('foo')
45+
end
46+
end
47+
end
3548

3649
RSpec.describe "Sentry::Rails::ActionCableExtensions", type: :channel do
3750
let(:transport) { Sentry.get_current_client.transport }

sentry-ruby/lib/sentry-ruby.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def init(&block)
174174
#
175175
# @return [Boolean]
176176
def initialized?
177-
!!@main_hub
177+
!!get_main_hub
178178
end
179179

180180
# Returns an uri for security policy reporting that's generated from the given DSN

0 commit comments

Comments
 (0)