Skip to content

Commit

Permalink
Hub#capture_message should check its argument's type (#1577)
Browse files Browse the repository at this point in the history
* Hub#capture_message should check the argument's type as well

* Update changelog
  • Loading branch information
st0012 committed Sep 22, 2021
1 parent 65a51e0 commit 4908a61
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
@@ -1,7 +1,9 @@
## Unreleased
## 4.7.3

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

## 4.7.2
Expand Down
10 changes: 6 additions & 4 deletions sentry-ruby/lib/sentry/hub.rb
Expand Up @@ -90,10 +90,10 @@ def start_transaction(transaction: nil, custom_sampling_context: {}, **options)
end

def capture_exception(exception, **options, &block)
return unless current_client

check_argument_type!(exception, ::Exception)

return unless current_client

options[:hint] ||= {}
options[:hint][:exception] = exception
event = current_client.event_from_exception(exception, options[:hint])
Expand All @@ -104,6 +104,8 @@ def capture_exception(exception, **options, &block)
end

def capture_message(message, **options, &block)
check_argument_type!(message, ::String)

return unless current_client

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

def capture_event(event, **options, &block)
return unless current_client

check_argument_type!(event, Sentry::Event)

return unless current_client

hint = options.delete(:hint) || {}
scope = current_scope.dup

Expand Down
6 changes: 6 additions & 0 deletions sentry-ruby/spec/sentry/hub_spec.rb
Expand Up @@ -149,6 +149,12 @@
expect(event_hash.dig(:threads, :values, 0, :stacktrace, :frames, 0, :function)).to eq("foo")
end

it "raises error when passing a non-string object" do
expect do
subject.capture_message(1)
end.to raise_error(ArgumentError, 'expect the argument to be a String, got Integer (1)')
end

it "assigns default backtrace with caller" do
event = subject.capture_message(message)
event_hash = event.to_hash
Expand Down

0 comments on commit 4908a61

Please sign in to comment.