From 13bb9e65be9f2a63931c820b76f65ea9d498eec1 Mon Sep 17 00:00:00 2001 From: st0012 Date: Thu, 11 Mar 2021 23:01:18 +0800 Subject: [PATCH 1/2] Exceptions with nil message shouldn't cause issues --- sentry-ruby/lib/sentry/interfaces/single_exception.rb | 2 +- sentry-ruby/spec/sentry/hub_spec.rb | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/sentry-ruby/lib/sentry/interfaces/single_exception.rb b/sentry-ruby/lib/sentry/interfaces/single_exception.rb index 4ff68dd17..8ba1b4727 100644 --- a/sentry-ruby/lib/sentry/interfaces/single_exception.rb +++ b/sentry-ruby/lib/sentry/interfaces/single_exception.rb @@ -4,7 +4,7 @@ class SingleExceptionInterface < Interface def initialize(exception:, stacktrace: nil) @type = exception.class.to_s - @value = exception.message.byteslice(0..Event::MAX_MESSAGE_SIZE_IN_BYTES) + @value = (exception.message || "").byteslice(0..Event::MAX_MESSAGE_SIZE_IN_BYTES) @module = exception.class.to_s.split('::')[0...-1].join('::') @thread_id = Thread.current.object_id @stacktrace = stacktrace diff --git a/sentry-ruby/spec/sentry/hub_spec.rb b/sentry-ruby/spec/sentry/hub_spec.rb index 70930ba26..5004820ca 100644 --- a/sentry-ruby/spec/sentry/hub_spec.rb +++ b/sentry-ruby/spec/sentry/hub_spec.rb @@ -157,6 +157,15 @@ end.to raise_error(ArgumentError, 'expect the argument to be a Exception, got String ("String")') end + # see https://github.com/getsentry/sentry-ruby/issues/1323 + it "don't causes error when the exception's message is nil" do + allow(exception).to receive(:message) + + expect do + subject.capture_exception(exception) + end.to change { transport.events.count }.by(1) + end + it_behaves_like "capture_helper" do let(:capture_helper) { :capture_exception } let(:capture_subject) { exception } From c22932c3899530f070bee70a57f82ce5218a72ac Mon Sep 17 00:00:00 2001 From: st0012 Date: Thu, 11 Mar 2021 23:08:54 +0800 Subject: [PATCH 2/2] Update changelog --- sentry-ruby/CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sentry-ruby/CHANGELOG.md b/sentry-ruby/CHANGELOG.md index c0c58a10c..2f4653ed8 100644 --- a/sentry-ruby/CHANGELOG.md +++ b/sentry-ruby/CHANGELOG.md @@ -27,6 +27,8 @@ config.max_breadcrumbs = 10 - Ignore sentry-trace when tracing is not enabled [#1308](https://github.com/getsentry/sentry-ruby/pull/1308) - Fixes [#1307](https://github.com/getsentry/sentry-ruby/issues/1307) - Return nil from logger methods instead of breadcrumb buffer [#1299](https://github.com/getsentry/sentry-ruby/pull/1299) +- Exceptions with nil message shouldn't cause issues [#1327](https://github.com/getsentry/sentry-ruby/pull/1327) + - Fixes [#1323](https://github.com/getsentry/sentry-ruby/issues/1323) ## 4.2.2