I'm trying to handle specific errors but I'm surprised about the behavior.
Examples:
If I use
if err == errors.New("something"){}`
it returns true
, even if err
is nil
.
If I use
if err.String() == "something"`
it panics when err
is nil
.
I really expected
err == errors.New("something")`
to work and I'm not sure why it returns true
.
Some more code:
Here is some code to clarify the question (Play):
package main
import "fmt"
import "errors"
func main() {
e := errors.New("error")
//I'm expecting this to return true
if e == errors.New("error") {
fmt.Println("Hello, playground")
}
}