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

New Check: Remind to handle functions which return an error. #1151

Closed
vidhanio opened this issue Dec 25, 2021 · 2 comments
Closed

New Check: Remind to handle functions which return an error. #1151

vidhanio opened this issue Dec 25, 2021 · 2 comments

Comments

@vidhanio
Copy link

vidhanio commented Dec 25, 2021

Sometimes, users may forget to handle errors. For example,

package something

import "errors"

func ReturnsAnError() error {
	return errors.New("handle me plz")
}
package main

import "something"

func main()
	something.ReturnsAnError() // Forgot to handle error! :(
}

This could be solved by a message showing that this function returns an error they forgot to handle. In cases where the user intentionally does not want to handle the error, they would be forced to make it explicit, using _ (Similar to how staticcheck asks you to make it explicit you meant time.Millisecond when using time.Sleep())

package main

import "something"

func main()
	_ := something.ReturnsAnError() // Forgot to handle error, but it is explicit and we know the user meant to not handle it.
}
@vidhanio vidhanio added the needs-triage Newly filed issue that needs triage label Dec 25, 2021
@vidhanio vidhanio changed the title Feature Request: Remind to handle functions which return an error. New Check: Remind to handle functions which return an error. Dec 25, 2021
@dominikh
Copy link
Owner

@dominikh dominikh added duplicate new-check wontfix and removed needs-triage Newly filed issue that needs triage labels Dec 25, 2021
@vidhanio
Copy link
Author

Interesting, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants