Skip to content

Commit 65e624e

Browse files
committed
syscall: document relationship among Errno, errors.Is and os.Err*
- Add doc to syscall.Errno (and syscall.ErrorString for plan9). - Mention under `syscall` in release notes. Fixes #33436. Change-Id: I032ffebaa76ed67eb9d748e7645ca73f26144ea0 Reviewed-on: https://go-review.googlesource.com/c/go/+/191337 Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent f3e3b71 commit 65e624e

File tree

6 files changed

+37
-0
lines changed

6 files changed

+37
-0
lines changed

doc/go1.13.html

+7
Original file line numberDiff line numberDiff line change
@@ -961,6 +961,13 @@ <h3 id="minor_library_changes">Minor changes to the library</h3>
961961
<a href="/pkg/syscall/?GOOS=windows#Chmod"><code>Chmod</code></a> mode on Windows.
962962
</p>
963963

964+
<p><!-- CL 191337 -->
965+
Values of type <code>Errno</code> can be tested against error values in
966+
the <code>os</code> package,
967+
like <a href="/pkg/os/#ErrExist"><code>ErrExist</code></a>, using
968+
<a href="/pkg/errors/#Is"><code>errors.Is</code></a>.
969+
</p>
970+
964971
</dl><!-- syscall -->
965972

966973
<dl id="syscall/js"><dt><a href="/pkg/syscall/js/">syscall/js</a></dt>

src/syscall/syscall_js.go

+6
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ const PathMax = 256
4444
// if errno != 0 {
4545
// err = errno
4646
// }
47+
//
48+
// Errno values can be tested against error values from the the os package
49+
// using errors.Is. For example:
50+
//
51+
// _, _, err := syscall.Syscall(...)
52+
// if errors.Is(err, os.ErrNotExist) ...
4753
type Errno uintptr
4854

4955
func (e Errno) Error() string {

src/syscall/syscall_nacl.go

+6
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ const PathMax = 256
5151
// if errno != 0 {
5252
// err = errno
5353
// }
54+
//
55+
// Errno values can be tested against error values from the the os package
56+
// using errors.Is. For example:
57+
//
58+
// _, _, err := syscall.Syscall(...)
59+
// if errors.Is(err, os.ErrNotExist) ...
5460
type Errno uintptr
5561

5662
func (e Errno) Error() string {

src/syscall/syscall_plan9.go

+6
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ const ImplementsGetwd = true
2020
const bitSize16 = 2
2121

2222
// ErrorString implements Error's String method by returning itself.
23+
//
24+
// ErrorString values can be tested against error values from the the os package
25+
// using errors.Is. For example:
26+
//
27+
// _, _, err := syscall.Syscall(...)
28+
// if errors.Is(err, os.ErrNotExist) ...
2329
type ErrorString string
2430

2531
func (e ErrorString) Error() string { return string(e) }

src/syscall/syscall_unix.go

+6
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ func (m *mmapper) Munmap(data []byte) (err error) {
107107
// if errno != 0 {
108108
// err = errno
109109
// }
110+
//
111+
// Errno values can be tested against error values from the the os package
112+
// using errors.Is. For example:
113+
//
114+
// _, _, err := syscall.Syscall(...)
115+
// if errors.Is(err, os.ErrNotExist) ...
110116
type Errno uintptr
111117

112118
func (e Errno) Error() string {

src/syscall/syscall_windows.go

+6
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ func UTF16PtrFromString(s string) (*uint16, error) {
7777
}
7878

7979
// Errno is the Windows error number.
80+
//
81+
// Errno values can be tested against error values from the the os package
82+
// using errors.Is. For example:
83+
//
84+
// _, _, err := syscall.Syscall(...)
85+
// if errors.Is(err, os.ErrNotExist) ...
8086
type Errno uintptr
8187

8288
func langid(pri, sub uint16) uint32 { return uint32(sub)<<10 | uint32(pri) }

0 commit comments

Comments
 (0)