Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
meetme2meat opened this issue May 11, 2021 · 0 comments · Fixed by #33
Closed

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

meetme2meat opened this issue May 11, 2021 · 0 comments · Fixed by #33

Comments

@meetme2meat
Copy link
Contributor

meetme2meat commented May 11, 2021

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

@meetme2meat meetme2meat changed the title return nil error always fail at err != nil nil error always fail at err != nil May 11, 2021
@meetme2meat meetme2meat changed the title nil error always fail at err != nil nil error always fail at err != nil check May 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant