-
-
Notifications
You must be signed in to change notification settings - Fork 505
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
NoMethodError: undefined method `byteslice' for []:Array #907
Comments
I think it doesn't make much sense to accept a non-string |
close with #1005 |
This scenario has a possible regression when the # frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
# Activate the gem you are reporting the issue against.
gem "sentry-ruby", "~> 5.11"
gem "rspec"
end
require "sentry-ruby"
require "rspec/autorun"
RSpec.describe "SentryClient" do
DUMMY_DSN = 'http://12345:[email protected]/sentry/42'
let(:configuration) do
Sentry::Configuration.new.tap do |config|
config.dsn = DUMMY_DSN
config.transport.transport_class = Sentry::DummyTransport
end
end
subject { Sentry::Client.new(configuration) }
it "converts non-string message" do
NonStringMessageError = Class.new(StandardError) { def message = { foo: "bar" } }
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\"}")
# Actual
# NoMethodError:
# undefined method `byteslice' for {:foo=>"bar"}:Hash
#
# @value = exception_message.byteslice(0..Event::MAX_MESSAGE_SIZE_IN_BYTES)
# ^^^^^^^^^^
end
end Fix seems to add the following: --- a/sentry-ruby/lib/sentry/interfaces/single_exception.rb
+++ b/sentry-ruby/lib/sentry/interfaces/single_exception.rb
@@ -22,6 +22,7 @@ module Sentry
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)) If the sentry team considers this a valid bug report, I would like to submit a fix patch. |
Hello,
Sidekiq integrations calls
Raven.capture_exception
like this:Unfortunately, if
ex.message
isn't a String (in our case, it was a Hash), it fails withNoMethodError: undefined method `byteslice' for []:Array
I know it's weird that
ex.message
isn't a String, but it works when calling it like this :When looking at code,
event.message
is interpolated properly only ifRaven.capture_exception
wasn't call with optionsmessage
Is it a bug ? I don't know, but I had to
to_s
my value before raising an exception.Thanks
The text was updated successfully, but these errors were encountered: