Skip to content

Instantly share code, notes, and snippets.

@davidbirdsong
Created May 16, 2016 01:12
Show Gist options
  • Select an option

  • Save davidbirdsong/92dea0aa4a3722f8e20bab602e76155d to your computer and use it in GitHub Desktop.

Select an option

Save davidbirdsong/92dea0aa4a3722f8e20bab602e76155d to your computer and use it in GitHub Desktop.
go errors rarely do what i expect
package main
import (
"crypto/x509"
"fmt"
"net/http"
)
func main() {
if req, err := http.NewRequest("GET", "https://too.long.s3.amazonaws.com/index.html ", nil); err != nil {
panic(err)
} else if _, err = http.DefaultClient.Do(req); err != nil {
if _, ok := err.(x509.HostnameError); ok {
fmt.Println("i'm x509.HostnameError!")
} else if _, ok = err.(x509.CertificateInvalidError); ok {
fmt.Println("i'm x509.CertificateInvalidError")
} else {
panic(fmt.Errorf("WTF i can't be coerced into anything: %v!", err))
}
}
}
@davidbirdsong
Copy link
Copy Markdown
Author

tried this on darwin/linux and go1.6.2 and built go from master (1.7-pre?)

@davidbirdsong
Copy link
Copy Markdown
Author

[david@foulplay x590test]$ gb build ./... 
cmd/x590test
[david@foulplay x590test]$ ../../../bin/x590test  
panic: WTF i can't be coerced into anything: Get https://too.long.s3.amazonaws.com/index.html%20: x509: certificate is valid for *.s3.amazonaws.com, s3.amazonaws.com, not too.long.s3.amazonaws.com!

goroutine 1 [running]:
panic(0x1d31a0, 0xc420427a50)
    /usr/local/go/src/runtime/panic.go:500 +0x18c
main.main()
    /Users/david/src/test1.7/src/cmd/x590test/m.go:21 +0x284

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment