]> Cypherpunks repositories - gostls13.git/commit
os: don't consult Is methods on non-syscall error types
authorDamien Neil <dneil@google.com>
Fri, 2 Aug 2019 18:18:56 +0000 (11:18 -0700)
committerDamien Neil <dneil@google.com>
Fri, 2 Aug 2019 21:09:50 +0000 (21:09 +0000)
commitd178c5888f06918e8dbd221f26c707e501a9fa98
treefaca9c7b6f04f490a882f0027b3958cc83a5bc78
parent55e23cb1fe18c6784b573a44bce4c798a1983c2f
os: don't consult Is methods on non-syscall error types

CL #163058 moves interpretation of platform-specific errors to the
syscall package. Package syscall errors implement an Is method which
os.IsPermission etc. consult. This results in an unintended semantic
change to the os package predicate functions: The following program
now prints 'true' where it used to print 'false':

package main
import "os"
type myError struct{ error }
func (e myError) Is(target error) bool { return target == os.ErrPermission }
func main() { println(os.IsPermission(myError{})) }

Change the os package error predicate functions to only examine syscall
errors, avoiding this semantic change.

This CL does retain one minor semantic change: On Plan9, os.IsPermission
used to return true for any error with text containing the string
"permission denied". It now only returns true for a syscall.ErrorString
containing that text.

Change-Id: I6b512b1de6ced46c2f1cc8d264fa2495ae7bf9f5
Reviewed-on: https://go-review.googlesource.com/c/go/+/188817
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
src/os/error.go
src/os/error_errno.go [new file with mode: 0644]
src/os/error_plan9.go [new file with mode: 0644]
src/os/error_test.go