From f7342596daa892400e91a407cac5843bc43dcdd0 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Fri, 13 Nov 2020 15:48:05 +0100 Subject: [PATCH] syscall: add DLLError.Unwrap function 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 TryBot-Result: Go Bot Reviewed-by: Alex Brainman Trust: Alex Brainman Trust: Jason A. Donenfeld --- doc/go1.16.html | 4 ++++ src/syscall/dll_windows.go | 2 ++ 2 files changed, 6 insertions(+) diff --git a/doc/go1.16.html b/doc/go1.16.html index a2f39893be9..92cadff7138 100644 --- a/doc/go1.16.html +++ b/doc/go1.16.html @@ -501,6 +501,10 @@ Do not send CLs removing the interior tags from such phrases.

SysProcAttr on Windows has a new NoInheritHandles field that disables inheriting handles when creating a new process.

+ +

+ DLLError on Windows now has an Unwrap function for unwrapping its underlying error. +

diff --git a/src/syscall/dll_windows.go b/src/syscall/dll_windows.go index c54feec56ae..d99da000896 100644 --- a/src/syscall/dll_windows.go +++ b/src/syscall/dll_windows.go @@ -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)