var errno syscall.Errno
if errors.As(err, &errno) {
switch errno {
- case syscall.ENOSYS, syscall.ENOTSUP:
- // Explicitly not supported.
- // TODO(#41198): remove these cases when errors.Is reports that they are
- // equivalent to ErrUnsupported.
- return true
case syscall.EPERM, syscall.EROFS:
// User lacks permission: either the call requires root permission and the
// user is not root, or the call is denied by a container security policy.
package syscall
import (
+ errorspkg "errors"
"internal/itoa"
"internal/oserror"
"sync"
// err = errno
// }
//
-// Errno values can be tested against error values from the os package
-// using errors.Is. For example:
+// Errno values can be tested against error values using errors.Is.
+// For example:
//
// _, _, err := syscall.Syscall(...)
// if errors.Is(err, fs.ErrNotExist) ...
return e == EEXIST || e == ENOTEMPTY
case oserror.ErrNotExist:
return e == ENOENT
+ case errorspkg.ErrUnsupported:
+ return e == ENOSYS || e == ENOTSUP || e == EOPNOTSUPP
}
return false
}
// ErrorString implements Error's String method by returning itself.
//
-// ErrorString values can be tested against error values from the os package
-// using errors.Is. For example:
+// ErrorString values can be tested against error values using errors.Is.
+// For example:
//
// _, _, err := syscall.Syscall(...)
// if errors.Is(err, fs.ErrNotExist) ...
package syscall
import (
+ errorspkg "errors"
"internal/bytealg"
"internal/itoa"
"internal/oserror"
// err = errno
// }
//
-// Errno values can be tested against error values from the os package
-// using errors.Is. For example:
+// Errno values can be tested against error values using errors.Is.
+// For example:
//
// _, _, err := syscall.Syscall(...)
// if errors.Is(err, fs.ErrNotExist) ...
return e == EEXIST || e == ENOTEMPTY
case oserror.ErrNotExist:
return e == ENOENT
+ case errorspkg.ErrUnsupported:
+ return e == ENOSYS || e == ENOTSUP || e == EOPNOTSUPP
}
return false
}
// Errno is the Windows error number.
//
-// Errno values can be tested against error values from the os package
-// using errors.Is. For example:
+// Errno values can be tested against error values using errors.Is.
+// For example:
//
// _, _, err := syscall.Syscall(...)
// if errors.Is(err, fs.ErrNotExist) ...
func (e Errno) Is(target error) bool {
switch target {
case oserror.ErrPermission:
- return e == ERROR_ACCESS_DENIED
+ return e == ERROR_ACCESS_DENIED ||
+ e == EACCES ||
+ e == EPERM
case oserror.ErrExist:
return e == ERROR_ALREADY_EXISTS ||
e == ERROR_DIR_NOT_EMPTY ||
- e == ERROR_FILE_EXISTS
+ e == ERROR_FILE_EXISTS ||
+ e == EEXIST ||
+ e == ENOTEMPTY
case oserror.ErrNotExist:
return e == ERROR_FILE_NOT_FOUND ||
e == _ERROR_BAD_NETPATH ||
- e == ERROR_PATH_NOT_FOUND
+ e == ERROR_PATH_NOT_FOUND ||
+ e == ENOENT
case errorspkg.ErrUnsupported:
- return e == EWINDOWS
+ return e == ENOSYS ||
+ e == ENOTSUP ||
+ e == EOPNOTSUPP ||
+ e == EWINDOWS
}
return false
}