You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was getting a weird error from Net::HTTPResponse, and noticed that a couple methods had some bad nil checking.
In read_body, it sets @body = nil and then later on calls string methods on it like @body.force_encoding. Right after you set @read = true you should add this code: return if @body.nil?.
Then, the weird error was from stream_check:
undefined method `closed?' for nil:NilClass (NoMethodError)
raise IOError, 'attempt to read body out of block' if @socket.closed?
Since you set @socket = nil in reading_body, the stream_check method should be:
defstream_checkraiseIOError,'attempt to read body out of block'if@socket.nil? || @socket.closed?end
The text was updated successfully, but these errors were encountered:
Here it is in patch form, for those who prefer that:
# frozen_string_literal: truerequire"net/http"beginresponse=Net::HTTPResponse.new("","","")response.bodyrescueIOError# We're goodrescue# Bad exceptionNet::HTTPResponse.class_execdoprivatedefstream_checkraiseIOError,"attempt to read body out of block"if@socket.nil? || @socket.closed?endendend
I was getting a weird error from Net::HTTPResponse, and noticed that a couple methods had some bad nil checking.
In
read_body
, it sets@body = nil
and then later on calls string methods on it like@body.force_encoding
. Right after you set@read = true
you should add this code:return if @body.nil?
.Then, the weird error was from
stream_check
:Since you set
@socket = nil
inreading_body
, thestream_check
method should be:The text was updated successfully, but these errors were encountered: