Skip to content

Commit

Permalink
Revert "[rails] support string errors in error reporter (#2464)" (#2533)
Browse files Browse the repository at this point in the history
* Revert "[rails] support string errors in error reporter (#2464)"

This reverts commit b31f0f3.

* Update CHANGELOG
  • Loading branch information
solnic authored Jan 29, 2025
1 parent 9a83d6e commit a8094be
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 40 deletions.
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

0 comments on commit a8094be

Please sign in to comment.