Skip to content

Commit

Permalink
Allow non-string error message to be reported to sentry (#2137)
Browse files Browse the repository at this point in the history
  • Loading branch information
the-spectator authored Nov 25, 2023
1 parent c4e4797 commit bebedc4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
- Fixed a deprecation in `sidekiq-ruby` error handler [#2160](https://github.com/getsentry/sentry-ruby/pull/2160)
- Avoid invoking ActiveSupport::BroadcastLogger if not defined [#2169](https://github.com/getsentry/sentry-ruby/pull/2169)
- Respect custom `Delayed::Job.max_attempts` if it's defined [#2176](https://github.com/getsentry/sentry-ruby/pull/2176)
- Allow non-string error message to be reported to sentry ([#2137](https://github.com/getsentry/sentry-ruby/pull/2137))
## 5.13.0
Expand Down
1 change: 1 addition & 0 deletions sentry-ruby/lib/sentry/interfaces/single_exception.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def initialize(exception:, stacktrace: nil)
else
exception.message || ""
end
exception_message = exception_message.inspect unless exception_message.is_a?(String)

@value = Utils::EncodingHelper.encode_to_utf_8(exception_message.byteslice(0..Event::MAX_MESSAGE_SIZE_IN_BYTES))

Expand Down
12 changes: 12 additions & 0 deletions sentry-ruby/spec/sentry/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,18 @@ def sentry_context
expect(hash[:exception][:values][0][:value]).to eq("undefined method `[]' for nil:NilClass")
end
end

it "converts non-string error message" do
NonStringMessageError = Class.new(StandardError) do
def detailed_message(*)
{ foo: "bar" }
end
end

event = subject.event_from_exception(NonStringMessageError.new)
expect(event).to be_a(Sentry::ErrorEvent)
expect(Sentry::Event.get_message_from_exception(event.to_hash)).to match("NonStringMessageError: {:foo=>\"bar\"}")
end
end

it "sets threads interface without stacktrace" do
Expand Down

0 comments on commit bebedc4

Please sign in to comment.