Why does PipeWriter.CloseWithError pretend to return an error?

44 views
Skip to first unread message

Glen Mailer

unread,
Jul 1, 2020, 12:31:01 PM7/1/20
to golang-nuts
Hi everyone,

We got bitten by a bug recently when using PipeWriter.CloseWithError. We incorrectly assumed it would pass-through the error it was passed.

The docs do say that it will always return `nil`, but does anyone know why it has an `error` return type at all?

I can't see an interface that it has to match, and couldn't think of any other reason.

Cheers
Glen


Ian Lance Taylor

unread,
Jul 1, 2020, 1:03:28 PM7/1/20
to Glen Mailer, golang-nuts
I think it's an unfortunate accident due to how the API was developed.
When CloseWithError was first introduced
(https://go.googlesource.com/go/+/6defc25c8383ab326e8c11af0c78de8a394dca84,
before the open source release) it could return an error. The API has
shifted a lot since then, and now it always returns a nil error. We
could have cleaned it up for Go 1, but nobody noticed.

Ian
Reply all
Reply to author
Forward
0 new messages