Ian Lance Taylor <i...@golang.org> writes: > On Thu, Sep 29, 2022 at 10:29 AM Rafael Ávila de Espíndola > <raf...@espindo.la> wrote: >> >> Currently errors.Is(syscall.ENOENT, fs.ErrNotExist) return true, but >> errors.Is(syscall.EINVAL, fs.ErrInvalid) returns false. As far as I can >> tell that is because of >> >> func (e Errno) Is(target error) bool { >> switch target { >> case oserror.ErrPermission: >> return e == EACCES || e == EPERM >> case oserror.ErrExist: >> return e == EEXIST || e == ENOTEMPTY >> case oserror.ErrNotExist: >> return e == ENOENT >> } >> return false >> } >> >> in syscall_unix.go missing an ErrInvalid case. Is that intentional? I >> see related issues showing up on github and being closed as duplicates >> of https://github.com/golang/go/issues/30322. Should I just add this >> case to that issue? > > Hi Rafael. > > It's easier to discuss this kind of thing with an example. Do you > have a test case where a function returns EINVAL and it would make > sense for errors.Is(err, fs.ErrInvalid) to return true? Thanks.
The function with witch I noticed this was mmap. If given a length of zero it returns EINVAL: https://cs.opensource.google/go/x/sys/+/f11e5e49:unix/syscall_unix.go;l=108 func (m *mmapper) Mmap(fd int, offset int64, length int, prot int, flags int) (data []byte, err error) { if length <= 0 { return nil, EINVAL } So having errors.Is return true when checking with fs.ErrInvalid seems reasonable. > If we want to make this change it should probably be done as a > proposal (https://go.dev/s/proposal). If the above sounds reasonable I can give it a try, but no promises on the timeline. > Ian Rafael -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/874jwqnhpr.fsf%40espindo.la.