Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hub#capture_message should check its argument's type #1577

Merged
merged 2 commits into from Sep 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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