]> git.ipfire.org Git - thirdparty/wireguard-go.git/commitdiff
device: simplify IpcHandle error handling
authorJosh Bleecher Snyder <josh@tailscale.com>
Mon, 25 Jan 2021 16:55:08 +0000 (08:55 -0800)
committerJosh Bleecher Snyder <josh@tailscale.com>
Mon, 25 Jan 2021 17:09:24 +0000 (09:09 -0800)
Unify the handling of unexpected UAPI errors.
The comment that says "should never happen" is incorrect;
this could happen due to I/O errors. Correct it.

Change error message capitalization for consistency.

Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
device/uapi.go

index 7d180bbc34e4b587ddef0b615d564b56a20fd757..160806d5e97f28afa1947c7c9199e32f6eb6587f 100644 (file)
@@ -411,31 +411,22 @@ func (device *Device) IpcHandle(socket net.Conn) {
        }
 
        // handle operation
-
-       var status *IPCError
-
        switch op {
        case "set=1\n":
                err = device.IpcSetOperation(buffered.Reader)
-               if err != nil && !errors.As(err, &status) {
-                       // should never happen
-                       status = ipcErrorf(1, "invalid UAPI error: %w", err)
-               }
-
        case "get=1\n":
                err = device.IpcGetOperation(buffered.Writer)
-               if err != nil && !errors.As(err, &status) {
-                       // should never happen
-                       status = ipcErrorf(1, "invalid UAPI error: %w", err)
-               }
-
        default:
-               device.log.Error.Println("Invalid UAPI operation:", op)
+               device.log.Error.Println("invalid UAPI operation:", op)
                return
        }
 
        // write status
-
+       var status *IPCError
+       if err != nil && !errors.As(err, &status) {
+               // I/O error, maybe something unexpected
+               status = ipcErrorf(1, "other UAPI error: %w", err)
+       }
        if status != nil {
                device.log.Error.Println(status)
                fmt.Fprintf(buffered, "errno=%d\n\n", status.ErrorCode())