Skip to content

nil error always fail at err != nil check #32

@meetme2meat

Description

@meetme2meat

Following is the sample code the output would say a lot here. I tried debugging this myself but unable to find why the behavior is such.

func main() {
	err := DBErr()
	if err != nil {
		fmt.Printf("Main err was not nil %T %v\n", err, err)
	} else {
		fmt.Println("Main", "err was nil")
	}
}

func DBErr() error {
	e := errors.Wrap(nil, 1)
	fmt.Println("DBErr() err is nil", e == nil)
	return e
}

Output:

DBErr() err is nil true
Main err was not nil *errors.Error <nil>

running go version

go version go1.16 darwin/amd64

following is my go.mod definition

module test-errors

go 1.16

require github.com/go-errors/errors v1.2.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions