Skip to content

Commit 5617ca3

Browse files
committed
Allow non-string error message to be reported to sentry
1 parent c4e4797 commit 5617ca3

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

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)