diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-03-10 02:37:34 +0100 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-03-10 03:37:23 +0100 |
commit | a9aa443ea78cf9926524dda8680a1e1a38d425c9 (patch) | |
tree | ac98e26149c9829900e84977569452a2a9274a56 /service/errors.go | |
parent | installer: bring to foreground using shellexec process (diff) | |
download | wireguard-windows-a9aa443ea78cf9926524dda8680a1e1a38d425c9.tar.xz wireguard-windows-a9aa443ea78cf9926524dda8680a1e1a38d425c9.zip |
service: keep track of proper errors
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to '')
-rw-r--r-- | service/errors.go | 103 |
1 files changed, 89 insertions, 14 deletions
diff --git a/service/errors.go b/service/errors.go index 04cedb45..ea6147a9 100644 --- a/service/errors.go +++ b/service/errors.go @@ -5,19 +5,94 @@ package service +import ( + "fmt" + "golang.org/x/sys/windows" + "syscall" +) + +type Error uint32 + +const ( + ErrorSuccess Error = iota + ErrorEventlogOpen + ErrorLoadConfiguration + ErrorCreateWintun + ErrorDetermineWintunName + ErrorUAPIListen + ErrorUAPISerialization + ErrorDeviceSetConfig + ErrorBindSocketsToDefaultRoutes + ErrorSetNetConfig + ErrorDetermineExecutablePath + ErrorFindAdministratorsSID + ErrorOpenNULFile + ErrorTrackTunnels + ErrorEnumerateSessions + ErrorWin32 +) + +func (e Error) Error() string { + switch e { + case ErrorSuccess: + return "No error." + case ErrorEventlogOpen: + return "Unable to open Windows event log." + case ErrorDetermineExecutablePath: + return "Unable to determine path of running executable." + case ErrorLoadConfiguration: + return "Unable to load configuration from path." + case ErrorCreateWintun: + return "Unable to create Wintun device." + case ErrorDetermineWintunName: + return "Unable to determine Wintun name." + case ErrorUAPIListen: + return "Unable to listen on named pipe." + case ErrorUAPISerialization: + return "Unable to serialize configuration into uapi form." + case ErrorDeviceSetConfig: + return "Unable to set device configuration." + case ErrorBindSocketsToDefaultRoutes: + return "Unable to bind sockets to default route." + case ErrorSetNetConfig: + return "Unable to set interface addresses, routes, dns, and/or adapter settings." + case ErrorFindAdministratorsSID: + return "Unable to find Administrators SID." + case ErrorOpenNULFile: + return "Unable to open NUL file." + case ErrorTrackTunnels: + return "Unable to track existing tunnels." + case ErrorEnumerateSessions: + return "Unable to enumerate current sessions." + case ErrorWin32: + return "An internal Windows error has occurred." + default: + return "An unknown error has occurred." + } +} + +func determineErrorCode(err error, serviceError Error) (bool, uint32) { + if syserr, ok := err.(syscall.Errno); ok { + return false, uint32(syserr) + } else if serviceError != ErrorSuccess { + return true, uint32(serviceError) + } else { + return false, windows.NO_ERROR + } +} + +func combineErrors(err error, serviceError Error) error { + if serviceError != ErrorSuccess { + if err != nil { + return fmt.Errorf("%v: %v", serviceError, err) + } else { + return serviceError + } + } + return err +} + const ( - ERROR_LOG_CONTAINER_OPEN_FAILED uint32 = 0x000019F1 - ERROR_INVALID_PARAMETER uint32 = 0x00000057 - ERROR_OPEN_FAILED uint32 = 0x0000006E - ERROR_ADAP_HDW_ERR uint32 = 0x00000039 - ERROR_PIPE_LISTENING uint32 = 0x00000218 - ERROR_BAD_LOGON_SESSION_STATE uint32 = 0x00000555 - ERROR_BAD_PATHNAME uint32 = 0x000000A1 - ERROR_FILE_NOT_FOUND uint32 = 0x00000002 - ERROR_SERVER_SID_MISMATCH uint32 = 0x00000274 - ERROR_NETWORK_BUSY uint32 = 0x00000036 - ERROR_NO_TRACKING_SERVICE uint32 = 0x00000494 - ERROR_OBJECT_ALREADY_EXISTS uint32 = 0x00001392 - ERROR_SERVICE_DOES_NOT_EXIST uint32 = 0x00000424 - ERROR_SERVICE_MARKED_FOR_DELETE uint32 = 0x00000430 + serviceDOES_NOT_EXIST uint32 = 0x00000424 + serviceMARKED_FOR_DELETE uint32 = 0x00000430 ) |