Skip to content
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

bcmills opened this issue Jun 6, 2020 · 1 comment

proposal: os: add ErrNotSupported #39436

bcmills opened this issue Jun 6, 2020 · 1 comment


Copy link

@bcmills bcmills commented Jun 6, 2020

We currently have many different syscall errors that indicate operations or functions that are not supported by the current platform:

  • syscall.EWINDOWS indicates an operation not supported by windows.
  • syscall.EPLAN9 indicates an operation not supported by plan 9.
  • On POSIX platforms:
    • ENOSYS indicates function not implemented.
    • ENOTSUP indicates functionality not supported or operation not supported.
    • EOPNOTSUPP indicates operation not supported on socket. On some platforms, it is identical to ENOTSUP.

However, none of those constants is portable: syscall.ENOSYS and syscall.ENOTSUP are not defined on plan9, and errors.Is(syscall.EWINDOWS, syscall.ENOSYS) returns false on Windows, requiring separate windows source files just to be able to name the error code.

In addition:

  • net/http, x/net/websocket, and cmd/go/internal/lockedfile/internal/filelock (see also #33974) all define errors named ErrNotSupported with similar semantics.
  • x/net/webdav and x/net/websocket both define similar errors named ErrNotImplemented, although websocket (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 named ErrNotSupported, with the error string operation not supported. Errors could define Is(os.ErrNotSupported) for any error that means “the operation is not supported for its operands, but the operands are not necessarily invalid”

The oserror and syscall packages would then be modified such that errors.Is(err, os.ErrNotSupported) returns true for all of syscall.EWINDOWS, syscall.EPLAN9, syscall.ENOSYS, syscall.ENOTSUP, and syscall.EOPNOTSUPP.

@gopherbot gopherbot added this to the Proposal milestone Jun 6, 2020
@gopherbot gopherbot added the Proposal label Jun 6, 2020
@rsc rsc added this to Incoming in Proposals Jun 10, 2020
Copy link

@carlmjohnson carlmjohnson commented Jul 22, 2020

If ErrNotSupported were an interface, you could implement it without importing package os.

Simplest way:

func IsErrNotSupported(err error) bool {
	var s interface {
		NotSupported() bool
	if errors.As(err, &s) {
		return s.NotSupported()
	return false

type myError struct {

func (me myError) NotSupported() bool { return true }

func main() {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants