Skip to content

Commit

Permalink
syscall: add DLLError.Unwrap function
Browse files Browse the repository at this point in the history
Because we're expecting for future functions to be unavailable, we
should add an Unwrap() function to the DLLError struct, so that people
can test for this situation easily via:

    if errors.Is(err, syscall.ERROR_PROC_NOT_FOUND) { ... }

DLLError already was wrapping the underlying Errno error, but never got
the Go 1.13 helper method.

Fixes golang#42584

Change-Id: I0f32a5146946b1b37a30897ba825a56faefc792c
Reviewed-on: https://go-review.googlesource.com/c/go/+/269761
Run-TryBot: Jason A. Donenfeld <[email protected]>
TryBot-Result: Go Bot <[email protected]>
Reviewed-by: Alex Brainman <[email protected]>
Trust: Alex Brainman <[email protected]>
Trust: Jason A. Donenfeld <[email protected]>
  • Loading branch information
zx2c4 committed Nov 21, 2020
1 parent f93ef07 commit f734259
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions doc/go1.16.html
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,10 @@ <h3 id="minor_library_changes">Minor changes to the library</h3>
<p><!-- CL 261917 -->
<a href="/pkg/syscall/#SysProcAttr"><code>SysProcAttr</code></a> on Windows has a new NoInheritHandles field that disables inheriting handles when creating a new process.
</p>

<p><!-- CL 269761, golang.org/issue/42584 -->
<a href="/pkg/syscall/#DLLError"><code>DLLError</code></a> on Windows now has an Unwrap function for unwrapping its underlying error.
</p>
</dd>
</dl><!-- syscall -->

Expand Down
2 changes: 2 additions & 0 deletions src/syscall/dll_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ type DLLError struct {

func (e *DLLError) Error() string { return e.Msg }

func (e *DLLError) Unwrap() error { return e.Err }

// Implemented in ../runtime/syscall_windows.go.

func Syscall(trap, nargs, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno)
Expand Down

0 comments on commit f734259

Please sign in to comment.