Skip to content

For *csv.ParseError, error.Is() comes back false and error.As() comes back true? #42004

@coreyog

Description

@coreyog

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

$ go version
go version go1.15.3 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=""
GOCACHE="/home/corey/.cache/go-build"
GOENV="/home/corey/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/corey/go/pkg/mod"
GONOPROXY="gitlab.com/ethopass/*"
GONOSUMDB="gitlab.com/ethopass/*"
GOOS="linux"
GOPATH="/home/corey/go"
GOPRIVATE="gitlab.com/ethopass/*"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build937491866=/tmp/go-build -gno-record-gcc-switches"

What did you do?

https://play.golang.org/p/SdpH9lJMVu1

I setup a reader that expects 2 fields per record and gave it some data with only 1 field. The csv.Reader returns a *csv.ParseError that contians the details about not containing enough fields.

When comparing against an empty *csv.ParseError, errors.Is() returns false and errors.As() returns true.

What did you expect to see?

I had the understanding that errors.Is and errors.As would return the same bool values when passed similar parameters indicating that the error is of that type. Either both would return true or both would return false. In this setup, I expected errors.Is(err, &csv.ParseError{}) to return true because the error is indeed a *csv.ParseError.

What did you see instead?

Instead, I find that errors.Is() returns false and errors.As() returns true when given similar parameters.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions