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

Revert "[rails] support string errors in error reporter (#2464)" #2533

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### Bug Fixes

- Fix handling of cron with tz in Cron::Job ([#2530](https://github.com/getsentry/sentry-ruby/pull/2530))
- Revert "[rails] support string errors in error reporter (#2464)" ([#2533](https://github.com/getsentry/sentry-ruby/pull/2533))

## 5.22.3

Expand Down
15 changes: 1 addition & 14 deletions sentry-rails/lib/sentry/rails/error_subscriber.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,7 @@ def report(error, handled:, severity:, context:, source: nil)
hint.merge!(context.delete(:hint))
end

options = { level: severity, contexts: { "rails.error" => context }, tags: tags, hint: hint }

case error
when String
Sentry::Rails.capture_message(error, **options)
when Exception
Sentry::Rails.capture_exception(error, **options)
else
log_debug("Expected an Exception or a String, got: #{error.inspect}")
end
end

def log_debug(message)
Sentry.configuration.logger.debug(message)
Sentry::Rails.capture_exception(error, level: severity, contexts: { "rails.error" => context }, tags: tags, hint: hint)
end
end
end
Expand Down
26 changes: 0 additions & 26 deletions sentry-rails/spec/sentry/rails_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -366,32 +366,6 @@ def capture_in_separate_process(exit_code:)

expect(transport.events.count).to eq(0)
end

it "captures string messages through error reporter" do
Rails.error.report("Test message", severity: :info, handled: true, context: { foo: "bar" })

expect(transport.events.count).to eq(1)
event = transport.events.first

expect(event.message).to eq("Test message")
expect(event.level).to eq(:info)
expect(event.contexts).to include({ "rails.error" => { foo: "bar" } })
expect(event.tags).to include({ handled: true })
end

it "skips non-string and non-exception errors" do
expect {
Sentry.init do |config|
config.logger = Logger.new($stdout)
end

Sentry.logger.debug("Expected an Exception or a String, got: #{312.inspect}")

Rails.error.report(312, severity: :info, handled: true, context: { foo: "bar" })
}.to output(/Expected an Exception or a String, got: 312/).to_stdout

expect(transport.events.count).to eq(0)
end
end
end
end
Loading