]> Cypherpunks repositories - gostls13.git/commitdiff
syscall: add DLLError.Unwrap function
authorJason A. Donenfeld <Jason@zx2c4.com>
Fri, 13 Nov 2020 14:48:05 +0000 (15:48 +0100)
committerJason A. Donenfeld <Jason@zx2c4.com>
Sat, 21 Nov 2020 07:37:02 +0000 (07:37 +0000)
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/go#42584

Change-Id: I0f32a5146946b1b37a30897ba825a56faefc792c
Reviewed-on: https://go-review.googlesource.com/c/go/+/269761
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
Trust: Alex Brainman <alex.brainman@gmail.com>
Trust: Jason A. Donenfeld <Jason@zx2c4.com>

doc/go1.16.html
src/syscall/dll_windows.go

index a2f39893be919bb1b5aef0ed36044a9df89dbcf3..92cadff7138403742aa8ff05f3a968f04f9acace 100644 (file)
@@ -501,6 +501,10 @@ Do not send CLs removing the interior tags from such phrases.
     <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 -->
 
index c54feec56aec2d6963729df6e5694c7710850d5f..d99da000896f74bd17e3f1dfe23bfe8564f84352 100644 (file)
@@ -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)