Skip to content

Commit bebedc4

Browse files
Allow non-string error message to be reported to sentry (#2137)
1 parent c4e4797 commit bebedc4

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
- Fixed a deprecation in `sidekiq-ruby` error handler [#2160](https://github.com/getsentry/sentry-ruby/pull/2160)
2626
- Avoid invoking ActiveSupport::BroadcastLogger if not defined [#2169](https://github.com/getsentry/sentry-ruby/pull/2169)
2727
- Respect custom `Delayed::Job.max_attempts` if it's defined [#2176](https://github.com/getsentry/sentry-ruby/pull/2176)
28+
- Allow non-string error message to be reported to sentry ([#2137](https://github.com/getsentry/sentry-ruby/pull/2137))
2829
2930
## 5.13.0
3031

sentry-ruby/lib/sentry/interfaces/single_exception.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def initialize(exception:, stacktrace: nil)
2222
else
2323
exception.message || ""
2424
end
25+
exception_message = exception_message.inspect unless exception_message.is_a?(String)
2526

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

sentry-ruby/spec/sentry/client_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,18 @@ def sentry_context
209209
expect(hash[:exception][:values][0][:value]).to eq("undefined method `[]' for nil:NilClass")
210210
end
211211
end
212+
213+
it "converts non-string error message" do
214+
NonStringMessageError = Class.new(StandardError) do
215+
def detailed_message(*)
216+
{ foo: "bar" }
217+
end
218+
end
219+
220+
event = subject.event_from_exception(NonStringMessageError.new)
221+
expect(event).to be_a(Sentry::ErrorEvent)
222+
expect(Sentry::Event.get_message_from_exception(event.to_hash)).to match("NonStringMessageError: {:foo=>\"bar\"}")
223+
end
212224
end
213225

214226
it "sets threads interface without stacktrace" do

0 commit comments

Comments
 (0)