Skip to content
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

Deal with the edge case in switch-case syntax. #1

Closed
Matts966 opened this issue Mar 7, 2019 · 0 comments

Comments

Projects
None yet
1 participant
@Matts966
Copy link

commented Mar 7, 2019

xerrchk can point out binary expressions comparing errors with ops such as != and ==. Such an expressions can lead to failure of error handling because wrapped errors should be unwrapped before comparison.
Also, the switch-case syntax leads to the same failure of handling errors, and some cases described below should be checked too.

func switchErrCase1(err error) string {
	switch err { // want `do not compare error with switch-case syntax as it leads to the failure of handling specific errors.`
	case sentinelErr:
		return "true"
	default:
		return "false"
	}
}

func switchErrCase2(err error) string {
	switch TestCauseFunc(err) { // OK
	case sentinelErr:
		return "true"
	default:
		return "false"
	}
}

func TestCauseFunc(err error) error {
	return error
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.