Skip to content

Commit 75c2e97

Browse files
committed
syscall: let ENOSYS, ENOTSUP and EOPNOTSUPP implement errors.ErrUnsupported
As suggested by Bryan, also update (Errno).Is on windows to include the missing oserror cases that are covered on other platforms. Quoting Bryan: > Windows syscalls don't actually return those errors, but the dummy Errno > constants defined on Windows should still have the same meaning as on > Unix. Updates #41198 Change-Id: I15441abde4a7ebaa3c6518262c052530cd2add4b Reviewed-on: https://go-review.googlesource.com/c/go/+/476875 TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Bryan Mills <[email protected]> Run-TryBot: Tobias Klauser <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent 8377f20 commit 75c2e97

File tree

5 files changed

+26
-17
lines changed

5 files changed

+26
-17
lines changed

src/internal/testenv/testenv_unix.go

-5
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@ func syscallIsNotSupported(err error) bool {
2424
var errno syscall.Errno
2525
if errors.As(err, &errno) {
2626
switch errno {
27-
case syscall.ENOSYS, syscall.ENOTSUP:
28-
// Explicitly not supported.
29-
// TODO(#41198): remove these cases when errors.Is reports that they are
30-
// equivalent to ErrUnsupported.
31-
return true
3227
case syscall.EPERM, syscall.EROFS:
3328
// User lacks permission: either the call requires root permission and the
3429
// user is not root, or the call is denied by a container security policy.

src/syscall/syscall_js.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
package syscall
88

99
import (
10+
errorspkg "errors"
1011
"internal/itoa"
1112
"internal/oserror"
1213
"sync"
@@ -47,8 +48,8 @@ const PathMax = 256
4748
// err = errno
4849
// }
4950
//
50-
// Errno values can be tested against error values from the os package
51-
// using errors.Is. For example:
51+
// Errno values can be tested against error values using errors.Is.
52+
// For example:
5253
//
5354
// _, _, err := syscall.Syscall(...)
5455
// if errors.Is(err, fs.ErrNotExist) ...
@@ -72,6 +73,8 @@ func (e Errno) Is(target error) bool {
7273
return e == EEXIST || e == ENOTEMPTY
7374
case oserror.ErrNotExist:
7475
return e == ENOENT
76+
case errorspkg.ErrUnsupported:
77+
return e == ENOSYS || e == ENOTSUP || e == EOPNOTSUPP
7578
}
7679
return false
7780
}

src/syscall/syscall_plan9.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ const bitSize16 = 2
2323

2424
// ErrorString implements Error's String method by returning itself.
2525
//
26-
// ErrorString values can be tested against error values from the os package
27-
// using errors.Is. For example:
26+
// ErrorString values can be tested against error values using errors.Is.
27+
// For example:
2828
//
2929
// _, _, err := syscall.Syscall(...)
3030
// if errors.Is(err, fs.ErrNotExist) ...

src/syscall/syscall_unix.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
package syscall
88

99
import (
10+
errorspkg "errors"
1011
"internal/bytealg"
1112
"internal/itoa"
1213
"internal/oserror"
@@ -97,8 +98,8 @@ func (m *mmapper) Munmap(data []byte) (err error) {
9798
// err = errno
9899
// }
99100
//
100-
// Errno values can be tested against error values from the os package
101-
// using errors.Is. For example:
101+
// Errno values can be tested against error values using errors.Is.
102+
// For example:
102103
//
103104
// _, _, err := syscall.Syscall(...)
104105
// if errors.Is(err, fs.ErrNotExist) ...
@@ -122,6 +123,8 @@ func (e Errno) Is(target error) bool {
122123
return e == EEXIST || e == ENOTEMPTY
123124
case oserror.ErrNotExist:
124125
return e == ENOENT
126+
case errorspkg.ErrUnsupported:
127+
return e == ENOSYS || e == ENOTSUP || e == EOPNOTSUPP
125128
}
126129
return false
127130
}

src/syscall/syscall_windows.go

+14-6
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ func UTF16PtrFromString(s string) (*uint16, error) {
103103

104104
// Errno is the Windows error number.
105105
//
106-
// Errno values can be tested against error values from the os package
107-
// using errors.Is. For example:
106+
// Errno values can be tested against error values using errors.Is.
107+
// For example:
108108
//
109109
// _, _, err := syscall.Syscall(...)
110110
// if errors.Is(err, fs.ErrNotExist) ...
@@ -147,17 +147,25 @@ const _ERROR_BAD_NETPATH = Errno(53)
147147
func (e Errno) Is(target error) bool {
148148
switch target {
149149
case oserror.ErrPermission:
150-
return e == ERROR_ACCESS_DENIED
150+
return e == ERROR_ACCESS_DENIED ||
151+
e == EACCES ||
152+
e == EPERM
151153
case oserror.ErrExist:
152154
return e == ERROR_ALREADY_EXISTS ||
153155
e == ERROR_DIR_NOT_EMPTY ||
154-
e == ERROR_FILE_EXISTS
156+
e == ERROR_FILE_EXISTS ||
157+
e == EEXIST ||
158+
e == ENOTEMPTY
155159
case oserror.ErrNotExist:
156160
return e == ERROR_FILE_NOT_FOUND ||
157161
e == _ERROR_BAD_NETPATH ||
158-
e == ERROR_PATH_NOT_FOUND
162+
e == ERROR_PATH_NOT_FOUND ||
163+
e == ENOENT
159164
case errorspkg.ErrUnsupported:
160-
return e == EWINDOWS
165+
return e == ENOSYS ||
166+
e == ENOTSUP ||
167+
e == EOPNOTSUPP ||
168+
e == EWINDOWS
161169
}
162170
return false
163171
}

0 commit comments

Comments
 (0)