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

Report a coding bug about unused result #171

Open
guodongli-google opened this issue Oct 2, 2021 · 0 comments
Open

Report a coding bug about unused result #171

guodongli-google opened this issue Oct 2, 2021 · 0 comments

Comments

@guodongli-google
Copy link

At https://github.com/GeertJohan/go.rice/blob/master/box.go#L66, the result of function errors.New is not actually used since err is local to case LocateFS such that errors.New("given name/path is not a directory") won't be assigned to the one declared outside the loop var err error.

var err error
for _, method := range order {
	...
	case LocateFS:
			// resolve absolute directory path
			err := b.resolveAbsolutePathFromCaller()
			...
			err = errors.New("given name/path is not a directory")
			continue
}

while function errors.New has no side effect:

func New(text string) error {
	return &errorString{text}
}

Another instance is at: https://github.com/GeertJohan/go.rice/blob/master/box.go#L83

A mini bug reproducer is available at:
https://play.golang.org/p/FA2ZsZ34zqJ

A possible fix is not to declare a local err within the cases, e.g.

	case LocateFS:
			// resolve absolute directory path
			err = b.resolveAbsolutePathFromCaller()

Found by static analyzer #deepgo

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

No branches or pull requests

1 participant