Skip to content

Commit

Permalink
syscall: document relationship among Errno, errors.Is and os.Err*
Browse files Browse the repository at this point in the history
- Add doc to syscall.Errno (and syscall.ErrorString for plan9).

- Mention under `syscall` in release notes.

Fixes golang#33436.

Change-Id: I032ffebaa76ed67eb9d748e7645ca73f26144ea0
Reviewed-on: https://go-review.googlesource.com/c/go/+/191337
Reviewed-by: Ian Lance Taylor <iant@golang.org>
  • Loading branch information
jba authored and t4n6a1ka committed Sep 5, 2019
1 parent 6c61578 commit 7126962
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 0 deletions.
7 changes: 7 additions & 0 deletions doc/go1.13.html
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,13 @@ <h3 id="minor_library_changes">Minor changes to the library</h3>
<a href="/pkg/syscall/?GOOS=windows#Chmod"><code>Chmod</code></a> mode on Windows.
</p>

<p><!-- CL 191337 -->
Values of type <code>Errno</code> can be tested against error values in
the <code>os</code> package,
like <a href="/pkg/os/#ErrExist"><code>ErrExist</code></a>, using
<a href="/pkg/errors/#Is"><code>errors.Is</code></a>.
</p>

</dl><!-- syscall -->

<dl id="syscall/js"><dt><a href="/pkg/syscall/js/">syscall/js</a></dt>
Expand Down
6 changes: 6 additions & 0 deletions src/syscall/syscall_js.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ const PathMax = 256
// if errno != 0 {
// err = errno
// }
//
// Errno values can be tested against error values from the the os package
// using errors.Is. For example:
//
// _, _, err := syscall.Syscall(...)
// if errors.Is(err, os.ErrNotExist) ...
type Errno uintptr

func (e Errno) Error() string {
Expand Down
6 changes: 6 additions & 0 deletions src/syscall/syscall_nacl.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ const PathMax = 256
// if errno != 0 {
// err = errno
// }
//
// Errno values can be tested against error values from the the os package
// using errors.Is. For example:
//
// _, _, err := syscall.Syscall(...)
// if errors.Is(err, os.ErrNotExist) ...
type Errno uintptr

func (e Errno) Error() string {
Expand Down
6 changes: 6 additions & 0 deletions src/syscall/syscall_plan9.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ const ImplementsGetwd = true
const bitSize16 = 2

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

func (e ErrorString) Error() string { return string(e) }
Expand Down
6 changes: 6 additions & 0 deletions src/syscall/syscall_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ func (m *mmapper) Munmap(data []byte) (err error) {
// if errno != 0 {
// err = errno
// }
//
// Errno values can be tested against error values from the the os package
// using errors.Is. For example:
//
// _, _, err := syscall.Syscall(...)
// if errors.Is(err, os.ErrNotExist) ...
type Errno uintptr

func (e Errno) Error() string {
Expand Down
6 changes: 6 additions & 0 deletions src/syscall/syscall_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ func UTF16PtrFromString(s string) (*uint16, error) {
}

// Errno is the Windows error number.
//
// Errno values can be tested against error values from the the os package
// using errors.Is. For example:
//
// _, _, err := syscall.Syscall(...)
// if errors.Is(err, os.ErrNotExist) ...
type Errno uintptr

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

0 comments on commit 7126962

Please sign in to comment.