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

Error must be checked before other code run #232

Open
lx-world opened this issue Mar 29, 2023 · 1 comment
Open

Error must be checked before other code run #232

lx-world opened this issue Mar 29, 2023 · 1 comment

Comments

@lx-world
Copy link

package main

import (
	"errors"
	"fmt"
	"os"
)

type Stu struct {
	Age int
}

func AAA() (*Stu, error) {
	return nil, errors.New("error here")
}

func BBB() (v int, err error) {
	stu, err := AAA() //lint must return if err != nil
	stu.Age = 1
	return
}

func main() {
	res, err := BBB()
	fmt.Fprintln(os.Stdout, res, err)
}

this code can't check the err not return, so it panic.

I hope that this situation can be warned, or whether it is turned on or not controlled by parameters

@dtcaciuc
Copy link
Collaborator

dtcaciuc commented Jul 3, 2024

Hm, there could very well be legitimate cases where one needs to run something before checking for error. For example, the one I had was where I wanted to issue a log statement regardless of whether error was nil or not.

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

2 participants