Skip to content

Commit 4908a61

Browse files
authored
Hub#capture_message should check its argument's type (#1577)
* Hub#capture_message should check the argument's type as well * Update changelog
1 parent 65a51e0 commit 4908a61

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
## Unreleased
1+
## 4.7.3
22

33
- Avoid leaking tracing timestamp to breadcrumbs [#1575](https://github.com/getsentry/sentry-ruby/pull/1575)
44
- Avoid injecting tracing timestamp to all ActiveSupport instrument events [#1576](https://github.com/getsentry/sentry-ruby/pull/1576)
5+
- Fixes [#1573](https://github.com/getsentry/sentry-ruby/issues/1574)
6+
- `Hub#capture_message` should check its argument's type [#1577](https://github.com/getsentry/sentry-ruby/pull/1577)
57
- Fixes [#1574](https://github.com/getsentry/sentry-ruby/issues/1574)
68

79
## 4.7.2

sentry-ruby/lib/sentry/hub.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,10 @@ def start_transaction(transaction: nil, custom_sampling_context: {}, **options)
9090
end
9191

9292
def capture_exception(exception, **options, &block)
93-
return unless current_client
94-
9593
check_argument_type!(exception, ::Exception)
9694

95+
return unless current_client
96+
9797
options[:hint] ||= {}
9898
options[:hint][:exception] = exception
9999
event = current_client.event_from_exception(exception, options[:hint])
@@ -104,6 +104,8 @@ def capture_exception(exception, **options, &block)
104104
end
105105

106106
def capture_message(message, **options, &block)
107+
check_argument_type!(message, ::String)
108+
107109
return unless current_client
108110

109111
options[:hint] ||= {}
@@ -114,10 +116,10 @@ def capture_message(message, **options, &block)
114116
end
115117

116118
def capture_event(event, **options, &block)
117-
return unless current_client
118-
119119
check_argument_type!(event, Sentry::Event)
120120

121+
return unless current_client
122+
121123
hint = options.delete(:hint) || {}
122124
scope = current_scope.dup
123125

sentry-ruby/spec/sentry/hub_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,12 @@
149149
expect(event_hash.dig(:threads, :values, 0, :stacktrace, :frames, 0, :function)).to eq("foo")
150150
end
151151

152+
it "raises error when passing a non-string object" do
153+
expect do
154+
subject.capture_message(1)
155+
end.to raise_error(ArgumentError, 'expect the argument to be a String, got Integer (1)')
156+
end
157+
152158
it "assigns default backtrace with caller" do
153159
event = subject.capture_message(message)
154160
event_hash = event.to_hash

0 commit comments

Comments
 (0)