-
Notifications
You must be signed in to change notification settings - Fork 17.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
proposal: os: add ErrNotSupported #39436
Comments
If func IsErrNotSupported(err error) bool {
var s interface {
error
NotSupported() bool
}
if errors.As(err, &s) {
return s.NotSupported()
}
return false
}
type myError struct {
error
}
func (me myError) NotSupported() bool { return true }
func main() {
fmt.Println(IsErrNotSupported(errors.New("nope")))
fmt.Println(IsErrNotSupported(myError{errors.New("yep")}))
} |
Is this now a duplicate of #41198? |
This proposal has been added to the active column of the proposals project |
This proposal has been added to the active column of the proposals project |
That seems als much better to me, because that would enable supporting it in your own programs too and even allow to add details why something is not supported. |
This proposal is a duplicate of a previously discussed proposal, as noted above, |
We currently have many different syscall errors that indicate operations or functions that are not supported by the current platform:
syscall.EWINDOWS
indicates an operationnot supported by windows
.syscall.EPLAN9
indicates an operationnot supported by plan 9
.ENOSYS
indicatesfunction not implemented
.ENOTSUP
indicatesfunctionality not supported
oroperation not supported
.EOPNOTSUPP
indicatesoperation not supported on socket
. On some platforms, it is identical toENOTSUP
.However, none of those constants is portable:
syscall.ENOSYS
andsyscall.ENOTSUP
are not defined onplan9
, anderrors.Is(syscall.EWINDOWS, syscall.ENOSYS)
returns false on Windows, requiring separatewindows
source files just to be able to name the error code.In addition:
net/http
,x/net/websocket
, andcmd/go/internal/lockedfile/internal/filelock
(see also proposal: os: make the internal lockedfile package public #33974) all define errors namedErrNotSupported
with similar semantics.x/net/webdav
andx/net/websocket
both define similar errors namedErrNotImplemented
, althoughwebsocket
(ironically!) does not appear to ever actually use it.We obviously can't collapse all of these errors back down into one. However, we can make them easier to manage!
I propose that we add a pre-defined error in the
os
package, tentatively namedErrNotSupported
, with the error stringoperation not supported
. Errors could defineIs(os.ErrNotSupported)
for any error that means “the operation is not supported for its operands, but the operands are not necessarily invalid”The
oserror
andsyscall
packages would then be modified such thaterrors.Is(err, os.ErrNotSupported)
returns true for all ofsyscall.EWINDOWS
,syscall.EPLAN9
,syscall.ENOSYS
,syscall.ENOTSUP
, andsyscall.EOPNOTSUPP
.The text was updated successfully, but these errors were encountered: