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

go2draft-error-handling-overview: Double io.Closer calls #27750

Open
RalphCorderoy opened this issue Sep 19, 2018 · 2 comments

Comments

@RalphCorderoy
Copy link

commented Sep 19, 2018

The examples in https://go.googlesource.com/proposal/+/master/design/go2draft-error-handling-overview.md arrange for w.Close() to be called more than once. https://golang.org/pkg/io/#Closer says
The behavior of Close after the first call is undefined. Specific implementations may document their own behavior.

The text before the code, and the problem:

On the other hand, the equivalent actual Go code today would be
Defers w.Close() and then calls w.Close().

For example, the corrected code above shortens to
checks w.Close() but also does that in an above handler.

It's OK for the double-Close to be one of the faults with the 'before', but it would be nice if the improved 'after' version didn't also do it. The more robust version with more helpful errors would be one in between doesn't.

CC: @rsc

@bcmills

This comment has been minimized.

Copy link
Member

commented Sep 19, 2018

See also #25408 (OnceCloser).

@bcmills

This comment has been minimized.

Copy link
Member

commented Sep 19, 2018

CC: @mpvl

@bcmills bcmills added this to the Unreleased milestone Sep 19, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.