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

Feature Request: support close inside function call #7

Open
dandandy opened this issue Aug 19, 2020 · 5 comments
Open

Feature Request: support close inside function call #7

dandandy opened this issue Aug 19, 2020 · 5 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@dandandy
Copy link

dandandy commented Aug 19, 2020

I would like to be able call a function to close my sqlx.Stmt structs to reduce dublicate code using a function like:

func closer(aStruct io.Closer) {
	err := aStruct.Close()
	if err != nil {
		logrus.Warnf("error closing sqlx statement %v", err)
	}
}
statement, err := db.Preparex(findUserOptions)
defer closer(statement)

But the version of sqlclosecheck in golangci-lint v1.30 will throw an error because it thinks I'm not closing the struct

pkg/database/client.go:174:34: Rows/Stmt was not closed (sqlclosecheck) statement, err := c.db.Preparex(findUserOptions)

If you think this feature is possible and worthwhile I'm interested in working on it

@ryanrolds
Copy link
Owner

I will see what I can do.

@ryanrolds ryanrolds added bug Something isn't working help wanted Extra attention is needed labels Oct 25, 2020
@vovanec
Copy link

vovanec commented Nov 16, 2020

Is there any estimate when this can be fixed?

@urgas9
Copy link

urgas9 commented Mar 8, 2021

big +1 this would help us too, we are wrapping the Close function in a helper function with signature db.CloseResource(ctx, resource)

@ocket8888
Copy link

This would be nice for some code I maintain, because I, too, have a wrapper function - log.Close(resource) - and my choices are to either do:

rows, err := tx.Query(query)
if err != nil {
    return err
}
defer rows.Close()

which causes a lint issue with errcheck because the error return isn't being checked, or:

rows, err := tx.Query(query)
if err != nil {
    return err
}
defer log.Close(rows)

which causes this lint "issue" to appear.

@ryanrolds
Copy link
Owner

I will spend some time on this project over the next few weeks. I will take a look at this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

5 participants