net/http: panic: runtime error: comparing uncomparable type when the underlying type has a map #29768
Comments
Yes, this is because ErrorResponse has So, when both
https://github.com/golang/go/blob/master/src/net/http/request.go#L652 A small reproducer - package main
import (
"fmt"
"net/http"
)
type ErrorResponse struct {
Message string
Headers http.Header `xml:"-" json:"-"`
}
// Error - Returns S3 error string.
func (e ErrorResponse) Error() string {
return e.Message
}
func main() {
hh := make(http.Header)
hh.Add("hi", "kk")
var e1 error = ErrorResponse{
Headers: hh,
}
fmt.Println(e1 == e1)
} @bradfitz - thoughts ? Since we are not in control of the underlying type, things like these can happen. |
Yeah, sorry, maps aren't comparable. This isn't an HTTP issue, really. |
Someone would easily define an error struct which has a map or a slice inside it to facilitate the construction of the error message. Since we cannot write a custom comparator in Golang for my custom error struct (ErrorResponse), it doesn't seem there is a way to avoid the panic without restructuring my code. With this additional context description, @bradfitz do you still feel this is not a http pkg issue ? |
My opinion is unchanged. You'll have to restructure your code so you don't do things not allowed by the language. |
What version of Go are you using (
go version
)?go version go1.10.4 linux/amd64
Does this issue reproduce with the latest release?
Not sure, the error is too rare for me but it seems the reason of the error is easy to discern.
What operating system and processor architecture are you using (
go env
)?What did you do?
Still, the error is so rare to be reproduced but it seems the reason of the error is easy to discern.
What did you expect to see?
No panic
What did you see instead?
More information
The following is the definition of minio.ErrorResponse (https://github.com/minio/minio-go/blob/master/api-error-response.go#L38)
The text was updated successfully, but these errors were encountered: