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'm trying to get a string from htmlContentReader which is a reader from http client response.
I have the following code:
// extract html from readerbuf:=&bytes.Buffer{}
_, err=buf.ReadFrom(htmlContentReader)
iferr!=nil {
logger.Err(err).Msg("there was an error during creating string from io.Reader")
returnpostData, err
}
htmlContent:=buf.String()
buf.ReadFrom(htmlContentReader) causes panic if a reader is empty (see src/bytes/buffer.go:204) - b.buf is not checked if it's empty and index anyway is used and this is the result:
I think error errEmptyReader or something like that should be returned in such case (instead of panicing) to handle this correctly - in my case, empty reader means empty webpage with statusCode=200 or statuscode=404, so I should simply "skip" processing of this page, I don't "expect" panic in such scenario.
The text was updated successfully, but these errors were encountered:
I don't know if it's intended behavior so I opened this issue
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I'm trying to get a string from
htmlContentReader
which is a reader from http client response.I have the following code:
buf.ReadFrom(htmlContentReader)
causes panic if a reader is empty (seesrc/bytes/buffer.go:204
) -b.buf
is not checked if it's empty and index anyway is used and this is the result:What did you expect to see?
I think error
errEmptyReader
or something like that should be returned in such case (instead of panicing) to handle this correctly - in my case, empty reader means empty webpage with statusCode=200 or statuscode=404, so I should simply "skip" processing of this page, I don't "expect" panic in such scenario.The text was updated successfully, but these errors were encountered: