Skip to content

Instantly share code, notes, and snippets.

@tyru
Last active March 31, 2018 17:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tyru/16d9afaffcb95584800d1fa13b8c658b to your computer and use it in GitHub Desktop.
Save tyru/16d9afaffcb95584800d1fa13b8c658b to your computer and use it in GitHub Desktop.
package main
import (
"errors"
"fmt"
multierror "github.com/hashicorp/go-multierror"
)
func main() {
a, err := f()
fmt.Printf("(1) err: %+v\n", err)
fmt.Printf("(1) err: %p\n", err)
fmt.Printf("(1) err != nil: %v\n", err != nil)
b, err := a.g()
fmt.Printf("(2) err: %+v\n", err)
fmt.Printf("(2) err: %p\n", err)
fmt.Printf("(2) err != nil: %v\n", err != nil)
fmt.Println(b)
}
type F struct{}
func f() (*F, error) {
return &F{}, errors.New("oops")
}
type G struct{}
func (*F) g() (*G, *multierror.Error) {
return &G{}, nil
}
$ go version
go version go1.10 linux/amd64
$ go run err.go
(1) err: "oops"
(1) err: oops
(1) err: 0xc42000e1e0
(1) err != nil: true
(2) err: <nil>
(2) err: <nil>
(2) err: 0x0
(2) err != nil: true
&{}
πŸ‘‡πŸ‘‡πŸ‘‡ ???????????????????????????????? πŸ‘‡πŸ‘‡πŸ‘‡
(2) err != nil: true
πŸ‘†πŸ‘†πŸ‘† ???????????????????????????????? πŸ‘†πŸ‘†πŸ‘†
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment