io: unexport ErrBadWriteCount

It was added in CL 240740 to fix #39978
but without any discussion of the exported API.

The error can still be returned to fix the issue,
without adding new public API to package io.

Also fix the error message to refer to lower-case write
like the other errors in the package.

Change-Id: I134de5eaf3ac903d73913c5cadcde904c5255d79
Reviewed-on: https://go-review.googlesource.com/c/go/+/262877
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
This commit is contained in:
Russ Cox 2020-10-15 23:32:51 -04:00
parent 83317d9e3c
commit 03f181a90e
3 changed files with 13 additions and 5 deletions

8
src/io/export_test.go Normal file
View File

@ -0,0 +1,8 @@
// Copyright 2020 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package io
// exported for test
var ErrInvalidWrite = errInvalidWrite

View File

@ -27,12 +27,12 @@ const (
// but failed to return an explicit error.
var ErrShortWrite = errors.New("short write")
// errInvalidWrite means that a write returned an impossible count.
var errInvalidWrite = errors.New("invalid write result")
// ErrShortBuffer means that a read required a longer buffer than was provided.
var ErrShortBuffer = errors.New("short buffer")
// ErrBadWriteCount means that a write returned an impossible count.
var ErrBadWriteCount = errors.New("Write returned impossible count")
// EOF is the error returned by Read when no more input is available.
// (Read must return EOF itself, not an error wrapping EOF,
// because callers will test for EOF using ==.)
@ -425,7 +425,7 @@ func copyBuffer(dst Writer, src Reader, buf []byte) (written int64, err error) {
if nw < 0 || nr < nw {
nw = 0
if ew == nil {
ew = ErrBadWriteCount
ew = errInvalidWrite
}
}
written += int64(nw)

View File

@ -441,7 +441,7 @@ func (w largeWriter) Write(p []byte) (int, error) {
}
func TestCopyLargeWriter(t *testing.T) {
want := ErrBadWriteCount
want := ErrInvalidWrite
rb := new(Buffer)
wb := largeWriter{}
rb.WriteString("hello, world.")