Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix exception event sending failed #2083

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
- Improve `TestHelper`'s setup/teardown helpers ([#2116](https://github.com/getsentry/sentry-ruby/pull/2116))
- Fixes [#2103](https://github.com/getsentry/sentry-ruby/issues/2103)
- Fix Sidekiq tracing headers not being overwritten in case of schedules and retries [#2118](https://github.com/getsentry/sentry-ruby/pull/2118)
- Fix exception event sending failed due to source sequence is illegal/malformed utf-8 [#2083](https://github.com/getsentry/sentry-ruby/pull/2083)
- Fixes [#2082](https://github.com/getsentry/sentry-ruby/issues/2082)

## 5.11.0

Expand Down
4 changes: 2 additions & 2 deletions sentry-ruby/lib/sentry/interfaces/single_exception.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
exception.message || ""
end

@value = exception_message.byteslice(0..Event::MAX_MESSAGE_SIZE_IN_BYTES)
@value = Utils::EncodingHelper.encode_to_utf_8(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
Expand Down Expand Up @@ -51,7 +51,7 @@
v = v.byteslice(0..MAX_LOCAL_BYTES - 1) + OMISSION_MARK
end

v
Utils::EncodingHelper.encode_to_utf_8(v)

Check warning on line 54 in sentry-ruby/lib/sentry/interfaces/single_exception.rb

View check run for this annotation

Codecov / codecov/patch

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

Added line #L54 was not covered by tests
rescue StandardError
PROBLEMATIC_LOCAL_VALUE_REPLACEMENT
end
Expand Down
60 changes: 60 additions & 0 deletions sentry-ruby/spec/sentry/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,66 @@ module ExcTag; end
end
end
end

describe "bad encoding character handling" do
context "if exception message contains illegal/malformed encoding characters" do
let(:exception) do
begin
raise "#{message}\x1F\xE6"
rescue => e
e
end
end

it "scrub bad encoding error message" do
expect { event.to_json_compatible }.not_to raise_error
version = Gem::Version.new(RUBY_VERSION)
if version >= Gem::Version.new("3.2")
expect(hash[:exception][:values][0][:value]).to eq("#{message}\x1F\uFFFD (RuntimeError)")
else
expect(hash[:exception][:values][0][:value]).to eq("#{message}\x1F\uFFFD")
end
end
end

context "if local variable contains illegal/malformed encoding characters" do
before do
perform_basic_setup do |config|
config.include_local_variables = true
end
end

after do
Sentry.exception_locals_tp.disable
end

let(:exception) do
begin
long = "*" * 1022 + "\x1F\xE6" + "*" * 1000
foo = "local variable \x1F\xE6"
raise message
rescue => e
e
end
end

it "scrub bad encoding characters" do
expect { event.to_json_compatible }.not_to raise_error
version = Gem::Version.new(RUBY_VERSION)
if version >= Gem::Version.new("3.2")
expect(hash[:exception][:values][0][:value]).to eq("#{message} (RuntimeError)")
frames = hash[:exception][:values][0][:stacktrace][:frames]
expect(frames[-1][:vars][:long]).to eq("*" * 1022 + "\x1F\uFFFD" + "...")
expect(frames[-1][:vars][:foo]).to eq "local variable \x1F\uFFFD"
else
expect(hash[:exception][:values][0][:value]).to eq(message)
frames = hash[:exception][:values][0][:stacktrace][:frames]
expect(frames[-1][:vars][:long]).to eq("*" * 1022 + "\x1F\uFFFD" + "...")
expect(frames[-1][:vars][:foo]).to eq "local variable \x1F\uFFFD"
end
end
end
end
end

describe "#generate_sentry_trace" do
Expand Down
Loading