Skip to content

io/fs: SubFS.Open returns incorrect errors for invalid paths #65419

@paulhammond

Description

@paulhammond

Go version

go version go1.21.1 linux/arm64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/home/vscode/.cache/go-build'
GOENV='/home/vscode/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/go/pkg/mod'
GONOPROXY='github.com/paulhammond'
GONOSUMDB='github.com/paulhammond'
GOOS='linux'
GOPATH='/go'
GOPRIVATE='github.com/paulhammond'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_arm64'
GOVCS=''
GOVERSION='go1.21.1'
GCCGO='gccgo'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/workspace/go.mod'
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 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build2551620224=/tmp/go-build -gno-record-gcc-switches'

What did you do?

The documentation for the fs.FS interface says:

Open should reject attempts to open names that do not satisfy ValidPath(name), returning a *PathError with Err set to ErrInvalid or ErrNotExist.

The errors returned by SubFS.Open() do not fulfill this contract, as demonstrated by https://go.dev/play/p/N5lvehlpeB5. Calling Open with an invalid path returns a *PathError with Err set to errors.New("invalid name") instead. This breaks any code that accepts an fs.FS and attempts to handle the documented errors.

What did you see happen?

err open ./: invalid name
isInvalid false
isNotExist false

What did you expect to see?

err open ./: invalid argument
isInvalid true
isNotExist false

Metadata

Metadata

Assignees

Labels

FixPendingIssues that have a fix which has not yet been reviewed or submitted.FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions