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
Properly handle closing files that have been writen to #7199
Conversation
| // HasEnvToken returns true when a token has been specified in an | ||
| // environment variable, else returns false. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated change that I wanted to make to improve this comment a bit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if we care enough about bubbling errors that result from file.Close() up to the user. I'd rather say that we'd want to ignore them, especially because gh is such a short-lived process. That way we could avoid restructuring whole functions with named return values.
Have you considered
defer func() {
_ = file.Close()
}()|
@mislav This is the same as the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right about legitimate filesystem errors potentially being masked. I was just skittish about this requiring significant code changes at first.
abbf23a
to
8695f8f
Compare
Addresses CodeQL warnings about properly handling the return value when closing a file that has been written to.
Fixes https://github.com/cli/cli/security/code-scanning/116
Fixes https://github.com/cli/cli/security/code-scanning/115
Fixes https://github.com/cli/cli/security/code-scanning/114
Fixes https://github.com/cli/cli/security/code-scanning/113