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

bufio: Scanner.Err() checks for io.EOF directly #58670

Closed
stevenh opened this issue Feb 23, 2023 · 2 comments
Closed

bufio: Scanner.Err() checks for io.EOF directly #58670

stevenh opened this issue Feb 23, 2023 · 2 comments

Comments

@stevenh
Copy link
Contributor

stevenh commented Feb 23, 2023

What version of Go are you using (go version)?

$ go version
go version go1.20.1 linux/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN="/data/go/bin"
GOCACHE="/home/steveh/.cache/go-build"
GOENV="/home/steveh/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOOS="linux"
GOPATH="/home/steveh/code"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.20.1"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOWORK=""
CGO_CFLAGS="-O2 -g"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-O2 -g"
CGO_FFLAGS="-O2 -g"
CGO_LDFLAGS="-O2 -g"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build2926415486=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Scanned from a reader which returned a wrapped io.EOF.
https://go.dev/play/p/HClzqB8deSR

What did you expect to see?

No errors.

What did you see instead?

The wrapped io.EOF was returned from scanner.Err().

I would expect the check to use errors.Is(s.err, io.EOF):

// Err returns the first non-EOF error that was encountered by the Scanner.
func (s *Scanner) Err() error {
	if errors.Is(s.err, io.EOF) {
		return nil
	}
	return s.err
}

And not the direct check:

// Err returns the first non-EOF error that was encountered by the Scanner.
func (s *Scanner) Err() error {
	if s.err == io.EOF {
		return nil
	}
	return s.err
}
@ianlancetaylor
Copy link
Contributor

Thanks, but as is documented at https://pkg.go.dev/io#Reader, a Read method should return io.EOF at end-of-file. It should not return an error that wraps io.EOF.

@ianlancetaylor ianlancetaylor closed this as not planned Won't fix, can't repro, duplicate, stale Feb 23, 2023
@stevenh
Copy link
Contributor Author

stevenh commented Feb 24, 2023

Ahh you learn something every day, not sure how well known that is but now I do :)

@golang golang locked and limited conversation to collaborators Feb 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants